0

Hi! I have made a desktop application which is running perfectly. But i am facing problems with jframe size on different machines.
I have monitor of 'Gateway'. I am satisfied with my jframe size on my screen . But when i shifted it on laptop of 'hp' company then my jframe and its child components appears very small.
For example I have a jframe named 'Home.java'. I set size of this jframe by following code

 java.awt.Dimension screenSize =                    Toolkit.getDefaultToolkit().getScreenSize();
 setSize(screenSize.width,screenSize.height);

On my monitor it appears very well i-e it takes monitor's screen size and flatters according that. But When i runs my program on 'hp' laptop it also flatters according to laptop's screen size but its child components(buttons and labels) appears very small.

Similarly I have a jframe named Sale.java. I have set its property resizeable(false).I do not need it to appear according to monitor's screen size. I have made this frame by giving a static size according to my desire.
On my pc when I runs program it appears very well i-e according to my given size and font size. But When I ran it on 'hp' laptop this jframe and its child components appear very small.

When I ran my program on 'Dell' laptop then my jframes and child components also appear with different size but not as small as on 'hp' laptop.

Is there any way that my jframes and their internal components appears in a good size according to machines.

3
Contributors
2
Replies
19
Views
2 Months
Discussion Span
Last Post by JamesCherrill
1

This is why Swing has Layout Managers. You start with the components (text fields, drop-down lists, whatever) which Java sizes to fit the text in them - nb this depends on the font you are using and the screen resolution. You use a layout manager to add these to the JFrame according to where you want them to go (top, bottom, etc). The Layout Manager then sets the size of the JFrame to fit your components according to the layout you wanted. This is done at run time so when you run on a different machine the frame is still sized appropriately. There is a decent choice of Layouit Managers, some simple, some less simple giving you detailed control over how things are spaced out, how they share the space when the frame is re-sized etc.
See https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.