Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I resize the rows in a Grid Layout?

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
Hello,

I have a Grid Layout:

Code:
JPanel mainpanel = new JPanel(new GridLayout(3,1,1,1));

The first and last row have text areas that are large, but the middle row is a button. How can I resize the middle cell the size of the button or close to it? because as of now I have enormouse amounts of gaps.

Thanks
 
With a GridLayout all grid 'squares' are constrained to be equal in size.

To gain finer-grained control over your layout, you would normally have JPanels within JPanels with various strategic layouts applied to each.

... or you could take the plunge and learn how to use the GridBaglayout which allows for more flexibility than the plain GridLayout, but at a price (it's hard to use).

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Ok thanks,

How about having one cell, but displaying items on their own line? For example right now I have a button and label side by side, can I have them on their own line?
 
When laying-out components in a container, I usually start with the positioning I want to achieve (scribbled on paper or using something like Visio), then I decide what combination of Panels/LayoutManagers is needed to do the job.

So, yes, you can have them on their own 'lines' but depending upon other considerations, you may not want to use a GridLayout.



Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Thanks, I am using the gridbag layout now, works much better for my needs on this task.

Quick question:
constraints.ipady = 15; makes my textarea larger, but how can I prevent it from resizing when I use the enter key and instead have scroll bars?

Thanks
 
Actually I am using constraints.ipady = 100; sorry.
 
I think the answer to that is to put your JTextArea onto a JScrollPane, then add the JScrollPane to your Container

Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top