[英]How to scale my JComponents in base of screen resolution\size in java?
I've a JPanel
with a lot of JComponents
inside it and I would like that the panel is ok regardless of screen size, so it can be seen on different monitors.我有一个JPanel
,里面有很多JComponents
,我希望无论屏幕大小如何,面板都可以,所以它可以在不同的显示器上看到。 I added scroll-bars to bypass this problem but it's not enough.我添加了滚动条来绕过这个问题,但这还不够。 Reading some tips on stackoverflow.com
and layout managers tutorial, I found out GridBagLayout's weightx\\weighty functionality and I thought to solve my problem in this way.阅读stackoverflow.com
和布局管理器教程上的一些提示,我发现了 GridBagLayout 的 weightx\\weighty 功能,我想以这种方式解决我的问题。 But there is something more to discover.但是还有更多的东西需要发现。 My JComponents have Font size, border size, hgap and vgap for some jpanels and I would like that even these constants to be dipendent from screen resize.我的 JComponents 有一些 jpanels 的字体大小、边框大小、hgap 和 vgap,我希望即使这些常量也能与屏幕调整大小相关。 How can I get this goal?我怎样才能达到这个目标? Thank you in advance.先感谢您。
This gets you your screen size .You can use dim.width
and dim.height
as a proportion for all your elements size .这为您提供屏幕尺寸。您可以使用dim.width
和dim.height
作为所有元素尺寸的比例。
Toolkit toolkit = Toolkit.getDefaultToolkit ();
Dimension dim = toolkit.getScreenSize();
myFrame.setSize(dim.width,dim.height);
The imports are java.awt.Toolkit
and java.awt.Dimension
导入是java.awt.Toolkit
和java.awt.Dimension
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.