Java应用程序自动调整大小以适应屏幕分辨率 [英] Java application automatically resize to fit screen resolution
问题描述
我正在开发的触摸屏应用程序将用于不同的屏幕分辨率。我以前从来没有担心过,但现在我做到了。我想知道如何设计GUI,以便GUI上的每个对象按比例调整大小以适应屏幕分辨率?你能把我推荐给一个好的教程页面吗?我正在使用NetBeans和Swing框架设计应用程序。谢谢
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
推荐答案
我想知道如何设计GUI以便GUI上的每个对象按比例调整大小以适应屏幕分辨率?
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
这就是为什么存在LayoutManagers ,
我建议使用 NestedLayout
确保有自定义
LayoutManagers
,例如使用MigLayout
(介于GridBagLayout
和SpringLayout
之间)可以将所有JComponent放入容器从一个地方,但我再次建议使用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
instead你必须设置(内部)用于在
JScrollPane
中显示内容的最小screenSize,例如分辨率小于1024 x 600的屏幕将使内容可滚动,否则让这个工作为LayoutManagers
,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 forLayoutManagers
,这个想法需要模型
JFrame
--->JScrollPane
--->JPanel
(父亲面板)在所有情况下,JScrollPane
将保护您的GUI免受小(和双重)屏幕分辨率的影响this idea required model
JFrame
--->JScrollPane
--->JPanel
(father panel) in all cases,JScrollPane
will protect your GUI against small (and dual too) screen resolutions您必须查看
FontMetrics
forFont
,因为你需要使用/ $ cc> c>大小大小的各种像素比率连续 JComponents
屏幕尺寸you have to look at
FontMetrics
forFont
, because you need in/decreaseFont
size for various pixel ratios continiously withJComponents
size on the screen与
图标相同
如果存在,准备之前在某些Graphics SW中,不在运行时调整大小same with
Icons
if exist, prepare that before in some of Graphics SW's, not resize on runtime我的观点--->基于
AWT / Swing
的任何框架
对于这种性质的工作来说不是有利的,my view ---> any
Framework
based onAWT/Swing
isn't advantage for job this nature,这篇关于Java应用程序自动调整大小以适应屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!