This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes swing components size based on screen resolution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "swing components size based on screen resolution" Watch "swing components size based on screen resolution" New topic
Author

swing components size based on screen resolution

selvakkumari paramasivam
Greenhorn

Joined: Mar 16, 2004
Posts: 2
i m developing gui with the screen resolution as 800 * 600.i have to convert the same gui to 1024 * 768 resolution.
is there any common method for solving this without changing the each components size?
anyone reply to this.
thanks in advance.
selvakkumari
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

What layout manager are you using? Most layout managers can handle this situation fine. If you aren't using a layout manager... Well, now you know why you need one.
[ March 16, 2004: Message edited by: Nathan Pruett ]

-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
selvakkumari paramasivam
Greenhorn

Joined: Mar 16, 2004
Posts: 2
i didn't use any layout manager.but i used the boxlayout for arranging the components in the panel.atlast i just add the panel to contentpane.
please tell me the posible way to handle the resolution problem with this.
thanks in advance.
Sammer Meer
Greenhorn

Joined: Mar 24, 2004
Posts: 19
Well i used something like this for a similar problem.. i dont know if it's the best way, but anyway here's what ive done
- i made an instance of the java.awt.Dimension class like this
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize()
Then i used relative dimensions to all the buttons and swing components i created,
e.g.
jb=new JButton();
jb.reshape(screenSize.getwidth()/2,screenSize.getLength()/4.....
seems stupid .. if someone else knows a smarter way please let us know


Ai no corrida..That's where I am<br />You send me there<br />Your dream is my command...
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

Originally posted by selvakkumari paramasivam:
i didn't use any layout manager.but i used the boxlayout for arranging the components in the panel.atlast i just add the panel to contentpane.
please tell me the posible way to handle the resolution problem with this.
thanks in advance.

BoxLayout wil honor preferred size of components. Instead of using setSize as final call, use pack and that should be good.
HTH,
- Manish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: swing components size based on screen resolution
 
Similar Threads
Using fixed size across varible display resolutions
Gui Implementation
JPanel.validate() repositions DnD Components
Getting Dimensions (Screen Size)dynamically
screen resolution problem