简体   繁体   English

GUI缩放以适应不同的屏幕分辨率和尺寸

[英]GUI scaling for different screen resolutions and sizes

As a beginner programmer I have been making very simple programs and dabbling in GUIs using Java. 作为一个初学者,我一直在编写非常简单的程序,并使用Java涉足GUI。 It occurred to me the other day that everything I have made is done and tested on the same resolution screen so I tried changing my resolution and the GUIs were just awful, half of them did not even fit all the components on to the screen. 有一天,我想到我所做的所有事情都在同一分辨率的屏幕上完成并经过测试,因此我尝试更改分辨率,GUI简直糟透了,其中一半甚至都没有适合屏幕上的所有组件。

I assume using scaling variables for the components is the solution but what do the pros typically use when scaling their apps? 我假设为组件使用缩放变量是解决方案,但是专业人士在缩放其应用程序时通常使用什么? I was thinking possibly getting the screen resolution/size ( I can't remember the tool for it but I've definitely seen it ) then scaling based on those results but perhaps there is a more simple technique that I haven't considered. 我当时在想可能要获得屏幕分辨率/大小(我不记得要使用它的工具,但我肯定看过它),然后根据这些结果进行缩放,但是也许有一种更简单的技术我没有考虑。

Typically you want to decide on a minimum supported screen resolution and design for that, using something like setPreferredSize(width, height) to size your top-level windows. 通常,您需要使用setPreferredSize(width, height)来确定顶级支持的最小屏幕分辨率和设计。 If the user has a larger-resolution screen, they can resize your application; 如果用户使用较大分辨率的屏幕,则可以调整应用程序的大小。 like MadProgrammer implied, your layout manager should be set up to resize gracefully. 就像MadProgrammer暗示的那样,应该设置布局管理器以优雅地调整大小。

If you really want to be responsive, you can isolate the code that sets up your layout manager in a method that takes the current screen resolution (that you can get using the method here ) and arrange components differently based on, say, the width of the screen. 如果您真的想响应,则可以将采用当前屏幕分辨率的方法(您可以在此处使用该方法获得的方法)中设置您的布局管理器的代码隔离开来,并根据(例如)屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM