This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problem with GridLayout. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply 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: 19216

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
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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Problem with GridLayout.
 
Similar Threads
how to resize a JSlider
AWT
Simple side-by-side layout manager?
JScrollPane and Canvas problem
Canvas in JScrollPane