Java application automatically resize to fit screen resolution

守給你的承諾、 提交于 2019-12-18 09:46:39

问题


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 using MigLayout (something betweens GridBagLayout and SpringLayout) is possible to put all JComponents to the container from one place, but again I'd be suggest use NestedLayout instead

  • you 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 for LayoutManagers,

  • this idea required model JFrame ---> JScrollPane ---> JPanel (father panel) in all cases, JScrollPane will protect your GUI against small (and dual too) screen resolutions

  • you have to look at FontMetrics for Font, because you need in/decrease Font size for various pixel ratios continiously with JComponents size on the screen

  • same with Icons if exist, prepare that before in some of Graphics SW's, not resize on runtime

  • my view ---> any Framework based on AWT/Swing isn't advantage for job this nature,



来源:https://stackoverflow.com/questions/10709561/java-application-automatically-resize-to-fit-screen-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!