• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with GridLayout.

 
Renjith mohanan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Renjith mohanan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic