• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which layout do you use for such a scenario?  RSS feed

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

GridBagLayout should do this job. But it's complicated. I'm wondering which layout do you use in this case? How about SpringLayout?

Thanks.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would probably use a combination of BorderLayout (outside) and FlowLayout (inside).

You might also want to take a look at the JGoodies FormLayout: http://www.jgoodies.com/freeware/forms/
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
I would probably use a combination of BorderLayout (outside) and FlowLayout (inside).

You might also want to take a look at the JGoodies FormLayout: http://www.jgoodies.com/freeware/forms/

I don't think it's a good idea.
1 It's not recommended to use many panels with different layouts to get the layout wanted. I got this from an article from Sun's java tip or other places. I can't remember. It's said that it's bad to performance that way.

2 The gap between every components is different. There is a biger gap between classLabel and nameTextField. I don't find FlowLayout can do this.

Finally, I use GridBagLayout to do this. It's not so complicated as I thought. Just take some time to get familiar with GridBagConstraints' attributes.

Yes. FormLayout is good! I used it one year ago. But I'm not allowed to introduce many jar files into my project. So I need to use the layouts JDK provieded.

Thanks any way.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Louis Wang:
1 It's not recommended to use many panels with different layouts to get the layout wanted. I got this from an article from Sun's java tip or other places. I can't remember. It's said that it's bad to performance that way.


What does "many" mean in this context?

We are actually using that strategy all the time, and it's working just fine. Performance doesn't seem to be too bad, and it seems to result in a quite flexible, reusable design, which is quite important to us.


2 The gap between every components is different. There is a biger gap between classLabel and nameTextField. I don't find FlowLayout can do this.


Well, you will probably not like this, but I'd probably have a label plus its textfield be one component with its own layout.


Finally, I use GridBagLayout to do this. It's not so complicated as I thought. Just take some time to get familiar with GridBagConstraints' attributes.


In my humble opinion, GridBagLayout is just horrible. You are allowed to disagree, but only on your own risk...

Yes. FormLayout is good! I used it one year ago. But I'm not allowed to introduce many jar files into my project. So I need to use the layouts JDK provieded.


There is always the option to write your own LayoutManager...
 
Brian Cole
Author
Ranch Hand
Posts: 937
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Louis Wang:
1 It's not recommended to use many panels with different layouts to get the layout wanted.


I completely disagree. Ilja Preuss has covered this already, but I concur that using subpanels with different layouts _is_ a recommended practice. I mention this lest any novices be convinced otherwise.

2 The gap between every components is different. There is a biger gap between classLabel and nameTextField. I don't find FlowLayout can do this.


There are many ways to do this. Ilja Preuss recommends subpanels. Alternatively, one could add borders [setBorder(BorderFactory.createEmptyBorder(pxTop, pxLeft, pxBottom, pxRight)] or use spacers [Box.createHorizontalStrut(pxWidth)].

I use GridBagLayout to do this.


If you like GridBagLayout then that's fine. I don't like it much, and usually recommend that novices avoid it.

[edit: Fix the quote blocks, plus it turns out ... doesn't underline.]
[ September 04, 2007: Message edited by: Brian Cole ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!