Reputation: 426
Is there a way to scale all the Swing components in an app by a single factor? I have an existing Swing app, and I want to display all the components at double size. Is this possible?
EDIT:
I'm porting a Java Swing app to Sugar (OLPC XO Graphics Environment). I don't have accessibility functionalities. The machine has only one resolution of 1200x900 in a 7.5” display. So the components are really small and unreadable.
Upvotes: 3
Views: 4940
Reputation: 81
If you place
System.setProperty("sun.java2d.uiScale","2")
at the very beginning of your main method, this will scale the entire application by a factor of 2. Other scaling factors are possible. If have tried this successfully with openJDK 11 on Windows 7 and Linux with KDE, both with System Look and Feel. Windows does accept fractional scaling factors, KDE does not.
If you do not want to modify the source code, a command-line option to the jvm will have the same effect:
java -Dsun.java2d.uiScale=2 -jar myApp.jar
Upvotes: 8
Reputation: 2976
You can use J(X)Layer for this (see www.pbjar.org/blogs/jxlayer/ but site seems down at the moment). An example which builds on it can be found here: http://patrickwebster.blogspot.com/2009/01/scalable-jfreechart-applet.html
Upvotes: 1
Reputation: 10143
Unluckily there is no such standart feature in Swing.
Every component size in application is determined by layout of the container where that component is added and component's preferred/minimum sizes, provided by their UIs.
So the best way (as i see it) is to modify standart UIs, so they provide additional preferred size (doubled in your case). But you will have to do that separately for each component of a certain type (buttons/checkboxes/tables/trees/scrolls e.t.c.). Plus you cannot change the system UIs - you could only extend some cross-platform Look and Feel like Metal LaF and that won't be useful at all in case you are using native Look and Feel.
You can change some default L&F properties though, like font:
UIManager.put ( "Button.font", new FontUIResource ( new Font ( "Arial", Font.BOLD, 20 ) ) );
This specific case changes only buttons font. There are also a lot of other components font properties that you can find in any LookAndFeel class (for e.g. BasicLookAndFeel).
Upvotes: 4
Reputation: 109813
is possible to scalling the Swing JComponents by using Nimbus Look and Feel
is very complicated to modify Nimbus L&F, its Color
, Insets
, Bounds
e.i., but in plain form without any issues
Upvotes: 4