views:

309

answers:

6
+2  A: 

You could use MiGLayout as your layout manager. It allows all kinds of customizations, including margins/paddings.

Joonas Pulakka
Thanks that could be an even better solution but currently I am reluctant to add another dependency to the project.
kroiz
A: 

What LayoutManager are you using? Adding margins is quite easy, it depends however on the specific LayoutManager used.

kgiannakakis
It is a vertical BoxLayout with horizontal Box(es).
kroiz
+2  A: 

Take a look to the GridBagLayoutManager. Its the most compex layout manager but everything can be acomplished whith it.

It uses the GridBagConstraintObject which has the inset property, it specifies the separation to the top, bottom, left and right components.

example: GridBagConstraintObject.insets.left=20

Telcontar
A: 

You could achieve a much better layout for the example above by using DesignGridLayout in just a couple of lines of code (one per row in your layout). DesignGridLayout will automatically use the correct spacing for the runtime platform.

besides I would highly suggest that you DON'T use TitledBorders in your form because it prevents ANY LayoutManager (as advanced as it may be) from automatically aligning correctly the various components across different groups. Instead you could use a JLabel with a JSeparator (there are examples in DesignGridLayout, but this works with any other LayoutManager).

jfpoilpret
oh, so this is how you solve the V align issue, great thanks.About the DesignGridLayout as I said: I am reluctant to add another dependency to the project.
kroiz
no problem with that! But you should be aware that working with "pure" Swing (without ANY 3rd-party library, not just for layout, but also for tables, special widgets...) is a big pain! Your choice anyway;-)
jfpoilpret
A: 

FormLayout is another good layout manager. With a good GUI editor like JFormDesigner it makes GUI building easy enough. JFormDesigner actually automatically adds sufficient padding in most cases. I have to recommend against using GridBagLayout. It does the job alright, but is very complex which makes it difficult to use and maintain.

Carlos
maybe, but I write open source and JFormDesigner is not free. maybe for others...
kroiz
+1  A: 
OscarRyz
That group layout seems great, I will give it a try.Does by using GroupLayout, the user must have at least Java 6 runtime?
kroiz
That's correct 1.6 is needed. I think if the user has < 1.6 you could take the source code of GroupLayout and ship it with your app. It is open source after all. I like this better than GridbagLayout because you don't need all those gridbagcontraints objects :)
OscarRyz