aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem with GridLayout. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with GridLayout." Watch "Problem with GridLayout." New topic
Author

Problem with GridLayout.

Renjith mohanan
Ranch Hand

Joined: Jun 19, 2009
Posts: 52
Hi All,

I created a Panel(ex: TopPanel) and set the layout of the panel to GridLayout(1,2).
And the panel (TopPanel) has two components. The components are also other panels(ex: TopPanel1 and TopPanel2).
Actually the problem is--- "I need to set the first component(TopPanel1) width to 75% of the TopPanel and other 25 % of the will take the TopPanel2".
I am using GridLayout, so the components (cell) will get equal width and height.
Is there any way to solve my problem with the GridLayout.
I not very flexible in using GridBagLayout, so that I need to with GridLayout.

Thanks In Advance.


Thanks
Renjith M :

Personal E-mail: kalliyoorrenjith@gmail.com
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

You said it yourself: GridLayout will divide the space equally between the components. You can't change that, that's just how it works.

Apart from GridBagLayout, I can't think of any layout manager that can do this. However, GridBagLayout is not that hard for this:
The only problem with this code is that the 75% - 25% will only kick in after the frame is resized enough. That's because it uses the preferred size of the buttons as the initial size. You can fix that by calling setPreferredSize on your components.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Renjith mohanan
Ranch Hand

Joined: Jun 19, 2009
Posts: 52
Thanks Rob.

Thank you very much for your time and help.

I used the code and set the preferredSize() method and I got the solution.


Thanks..
Renjith M
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with GridLayout.
 
Similar Threads
AWT
JScrollPane and Canvas problem
Simple side-by-side layout manager?
how to resize a JSlider
Canvas in JScrollPane