1

I made a custom Windows desktop app and for now everything looked good but I want it to be as good as possible. The JPanel I used in the dock has round corners but when you look closer, the edges are not blurred or smooth. Is there some easy way to fix that?

Here is a screenshot of the dock:

enter image description here

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user204855
  • 55
  • 4
  • How did you make the rounded corners? I don't really understand which part of the image you made and which part of the image is just windows. – matt Aug 12 '20 at 11:13
  • @matt This is the code that I used for making the corners round. setShape(new RoundRectangle2D.Double(0, 0, width, height, height, height)); Don't mind the variables. The whole program is the translucent bar in the picture. I set is as undecored and made a utility. Here is screenshot of the whole screen so you have a better idea of what are you looking at: https://imgur.com/RmDnYrM – user204855 Aug 12 '20 at 13:51
  • So this the jframe that you have set the shape for? – matt Aug 12 '20 at 13:58
  • When you use a graphics to paint components and such, you can add [RenderingHings](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/RenderingHints.html) that make it paint much better. I would suggest trying to override 'paint' in your window, then set some anti aliasing, then call `super.paint(g);` I woudl test it out, but using set shape doesn't work at all for me. – matt Aug 12 '20 at 14:18
  • What you are probably experiencing is [this jdk bug](https://bugs.openjdk.java.net/browse/JDK-8215980?attachmentOrder=desc). If you provide the code you are using to create the effect (stripped of any unnecessary parts) I might be able to help you, as I have faced the same issue myself before. – weisj Aug 12 '20 at 17:44

2 Answers2

1

Unfortunately it's problematic as Swing is not designed for high DPI aware displays.

Here is a discussion of approaches to try hiDPI look and feel, however as far as running the app on Windows you can always alter the compatibility settings as Windows by default will assume the app is DPI aware and will not attempt to scale it (right click on the desktop icon, then on the compatibility tab change high DPI settings.)

As @weisj has suggested updating to jdk 9+ may fix this, however subsequently a bug has been identified per the comments below. I looked up the openjdk notes on this JEP263 HiDPI graphics and it looks as if the work has been done to support modern displays. That does of course impose additional work for the users so may not be practical. As always it depends what the actual results look like.

Andrew
  • 2,598
  • 16
  • 27
  • Thank you. I will look into it but unfortunately java apps don't have compatibility tab. – user204855 Aug 12 '20 at 09:25
  • Feel free to upvote if helpful. Best bet is take a look at javafx https://gluonhq.com/products/javafx/ which is more modern. – Andrew Aug 12 '20 at 09:35
  • Re the compatibility tab issue if you use something like Launch4j (haven't used this myself though) you can package the jar as an exe. Each exe has a manifest and in there are compatibility settings. – Andrew Aug 12 '20 at 09:49
  • I have used Launcher4J in the past but this would require the user to set it up and I want it to be as simple as pressing a button and everything works as it should. I found a solution using JNA library that blures the background. It is not something I was looking for but it definitely looks very good. – user204855 Aug 12 '20 at 10:06
  • 1
    Honestly this doesn't seem to be an issue with hiDPI settings. Swing is actually designed for hiDPI displays as long as you are using a version greater than or equal to Java 9 (Which @user204855 probably has the freedom to do so). It would be a lot more interesting to see the code used to create the desired effect. I believe what we are experiencing is the a known [bug/limitation of the the jdk](https://bugs.openjdk.java.net/browse/JDK-8215980?attachmentOrder=desc). – weisj Aug 12 '20 at 17:42
0

Activate antialiasing in paintComponent() and draw your RoundRectangle2D.

Example: Antialiasing in Swing