Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to scale to screen resolution?

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a small problem - my Java applcation is supposed to run (and look good) both on 640x480 and on 1024x768 resolutions. So I wondered if there's a way to scale gui programmatically, so that it'll take the same amount of screen space on both?
Thanks, hope somebody will answer
KathyS
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can use getScreenSize() in Toolkit (an instance of which can be obtained from Toolkit.getDefaultToolkit()). Once your program knows the dimensions of the screen, you can use that info to decide on the outer dimensions of your window(s). The inner dimensions of other components within the windows will then be managed by your layout managers.
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi kathy,
there is one more method in Toolkit class getScreenResolution().that returns the screen resolution in dots-per-inch. may be u can make use of it.
regards
deekasha
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jim and Deekasha.
I remember trying to set frame size dependent on screen resolution, but it doesn't seem to change size of the font. So buttons, for example, will drop some text instead of resizing it. Certainly I could keep going and parameterize everything... I just hoped there was an easy way out
KathyS
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually this is where layout managers come into play. Once you set the size of your frame, if you use the right combination of layout managers, the resizing should take care of itself.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carl,
Could you please elaborate on 'right combination' of layout managers? I tried Grid Layout with no success.
KathyS
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing your code, or what your screen design looks like I can only speculate. What I've done in the past is used the BorderLayout in my frame, put a panel in the north position, set the panels layout manager to flow. this allowed the Components that I added to the panel to be the default size of the component. If your doing a gridbag, you can do something similar an add a panel to each location an set the layoutmanager to something that will give the appearance that you need. If your design is elabarate, this might not be any less work than what you proposed above.
 
Phill Dixon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Sorry to ask this but could you elaborate on the layout managers to use, I want to be able to scale my JLabels and JTables in aspect ratio.

I would also like the text not to be cropped but to scale to the available space.

Any help would be greatly appreciated
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic