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. 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. 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. How can I get this goal? Thank you in advance.
Asked
Active
Viewed 1,359 times
0

user2896152
- 762
- 1
- 9
- 32
-
1*"My question is fairly simple..."* DYM 'simple like in *"What is the meaning of life?"*? There are many questions which are simple to define, simple to ask, but have ..not so simple answers (if they have any answer at all). This is one of those cases. Making the fonts & components of a GUI scale to user need is anything but simple. See [this answer](http://stackoverflow.com/a/21066065/418556) for a start on the problem. It aims to scale the font sizes of the calculator buttons to the largest size that they will support. – Andrew Thompson Jul 28 '15 at 18:41
1 Answers
0
This gets you your screen size .You can use dim.width
and dim.height
as a proportion for all your elements size .
Toolkit toolkit = Toolkit.getDefaultToolkit ();
Dimension dim = toolkit.getScreenSize();
myFrame.setSize(dim.width,dim.height);
The imports are java.awt.Toolkit
and java.awt.Dimension

Kibadachi
- 155
- 6
-
1[`Frame.setExtendedState(Frame.MAXIMIZED_BOTH)`](http://docs.oracle.com/javase/8/docs/api/java/awt/Frame.html#setExtendedState-int-) is an easier and more reliable (in that it accounts for the task bar) way to achieve what that code does. But then, making the parent container as big as it can be is not really related to the problem, which is getting the GUI components to scale to *whatever size* the user assigns to the application window. – Andrew Thompson Jul 28 '15 at 18:38