File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes how to scale to screen resolution? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to scale to screen resolution?" Watch "how to scale to screen resolution?" New topic
Author

how to scale to screen resolution?

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jun 13, 2000
Posts: 3340
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.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Carl,
Could you please elaborate on 'right combination' of layout managers? I tried Grid Layout with no success.
KathyS
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
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

Joined: Apr 01, 2005
Posts: 3
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
 
jQuery in Action, 2nd edition
 
subject: how to scale to screen resolution?