Results 1 to 4 of 4
Thread: A few question about FlowLayout
- 03-23-2009, 07:10 PM #1Member
- Join Date
- Mar 2009
- Rep Power
A few question about FlowLayout
FlowLayout is easy to use and useful enough, but sometimes I want two things to remain associated with each other, like a label and a text field, and not split apart at the edge. I make a sub-panel, add the label and the text field to that, then add the sub-panel to my super-panel, and that seems to work fine. But is there an easier or better way?
On the other hand, sometimes I want an item to appear on the next line, even if there's room for it on the line above. For that, I play tricks with a sub-panel with a BorderLayout or GridLayout or something. But it would be really nice if there was a "NewLine" object that tells FlowLayout to start a new line. Is there such a thing?
Actually, it would be nice if FlowLayout had tab stops, too. It would be easy to line up buttons and fields without having to muck around with a GridBag or a bunch of sub-panels.
I usually nest layouts. For instance one way to have a column of x JLabels and a column of x matching JTextFields (and avoid GridBagLayout) is to put the labels in a JPanel (I call labelPanel) that uses GridLayout(0, 1, 0, 5) which stands for 1 column, 5 points between labels, and then put the JTextFields in a JPanel (I call fieldPanel) that uses the exact same layout. Then place the labelPanel BorderLayout.WEST into a JPanel that uses BorderLayout, and the fieldPanel BorderLayout.CENTER into the same BorderLayout panel. Play with it and have fun.
Last edited by Fubarable; 03-23-2009 at 09:49 PM.
- 03-23-2009, 09:51 PM #3Senior Member
- Join Date
- Nov 2008
- Rep Power
There's no single standard layout that'll do this. Solutions could be:
- create a vertical Box, to which you add panels with FlowLayouts
- create your own layoutNeil Coffey
Javamex - Java tutorials and performance info
I've also heard good things about the MiG layout. It's not part of the Java core library, but some folks in this forum, the Sun fora, and JavaRanch Swing fora rave about it. I've never used it, but am thinking about trying it out. It can be found here: MiG Layout Java Layout Manager for Swing and SWT
- By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM
- By anjogomez in forum Java AppletsReplies: 2Last Post: 02-21-2009, 03:24 AM
- By htetnaing in forum New To JavaReplies: 3Last Post: 01-26-2009, 03:49 PM
- By chris12295 in forum New To JavaReplies: 1Last Post: 12-07-2007, 05:49 PM
- By toad in forum New To JavaReplies: 2Last Post: 12-03-2007, 12:43 AM