问题
The touch-screen application I am developing will be used on different screen resolutions. I never had to worry about this before, but now I do. I am wondering how can I design the GUIs so that EVERY object on the GUI resizes proportionally to fit the screen resolution? Can you refer me to a good tutorial page? I am designing the application using the NetBeans and the Swing framework. Thank you
回答1:
I am wondering how can I design the GUIs so that EVERY object on the GUI resizes proportionally to fit the screen resolution?
not easy job you have to test all possible pixels ratio that exist (by default is possible to change and set various pixels ratio on todays fullHD screen) with lot of fails
this is reason why LayoutManagers exist,
I'd suggest to use NestedLayout
sure there are custom
LayoutManagers
, for example by usingMigLayout
(something betweensGridBagLayout
andSpringLayout
) is possible to put all JComponents to the container from one place, but again I'd be suggest useNestedLayout
insteadyou have to set (internally) minimum screenSize for displaying contents in the
JScrollPane
, for example screen with resolutions less than 1024 x 600 will have the content scrollable, otherwise let's this job forLayoutManagers
,this idea required model
JFrame
--->JScrollPane
--->JPanel
(father panel) in all cases,JScrollPane
will protect your GUI against small (and dual too) screen resolutionsyou have to look at
FontMetrics
forFont
, because you need in/decreaseFont
size for various pixel ratios continiously withJComponents
size on the screensame with
Icons
if exist, prepare that before in some of Graphics SW's, not resize on runtimemy view ---> any
Framework
based onAWT/Swing
isn't advantage for job this nature,
来源:https://stackoverflow.com/questions/10709561/java-application-automatically-resize-to-fit-screen-resolution