3

I made a program using several JFrames on a Mac, and the resolution was okay, everything fit the screen properly. But when I run the program on my PC the JFrames are way too large and go right off the screen.

My question is: Is it possible to set the universal resolution on a JFrame so that all the components are drawn a little smaller? I would rather do that then go through the entire program and resize every component manually.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Blackvein
  • 558
  • 4
  • 10
  • 23
  • *"I made a program using several JFrames.."* See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) *"Is it possible to set the universal resolution on a JFrame so that all the components are drawn a little smaller?"* I hope not! Having a GUI on my screen where the text is 'too small' (read 'smaller than standard') would be of no use to me. Use layouts to make a compact (e.g. `CardLayout`) & resizable GUI. If all else fails, drop the content pane into a scroll-pane (but the situation would have to be dire to justify that). – Andrew Thompson Apr 29 '12 at 23:10

3 Answers3

5

I made a program using several JFrames

wrong use CardLayout instead, only if is there real reason use JDialog or JOptionPane with parent and (JDialog) maybe with setModal(true) to the single JFrame

But when I run the program on my PC the JFrames are way too large and go right off the screen

Is it possible to set the universal resolution on a JFrame so that all the components are drawn a little smaller?

use proper LayoutManager, sure not easy job, required real effort

I would rather do that then go through the entire program and resize every component manually.

use proper LayoutManager,

  • for better help sooner edit your question with SSCCE demonstrated your issue with different screen size betweens PC's or platforms
Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Thank you! I think you misunderstood what I meant by 'multiple JFrames' though. I just meant that the entire program involves more than one, they don't all show up at once though :P I am using absolute layout, so I'll fiddle around with the layouts that have been recommended and see what I can do to fix my problem. – Blackvein Apr 30 '12 at 15:06
4

As far as I know you can't change the resolution of Swing components. But you can get the current screen size from the system (here's an example). With this screen size you can adjust your components.

If you are coding your GUI wisely, you wouldn't have to resize all your components of your GUI manually. Instead, a top-level JPanel (or JFrame or what ever) will adjust its size due to its contained components (e.g. with something like pack()). So only a few components will have a hard coded size. This size could also be externalized into a class or a file that is easy to edit.

Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80
0

I had encountered a problem like your's and I solved it with a JScrollbar! Here is how to make your JFrame scrollable.

Community
  • 1
  • 1
Moh Mah
  • 2,005
  • 20
  • 29