How to neatly defer some components using Java Swing layouts

Using Swing, what's the best way to highlight some components under a checkbox or radio button? I need to do something in the style of Firefox 3.6 Options-> Privacy dialog, where some checkboxes drop back under the “main” checkbox. I can use any standard AWT / Swing layout, including GroupLayout. I also have JGoodies FormLayout for me. At first I tried to compile setLeadingColumn into FormLayout, but it seemed that it would not work well if I did not fall back under the Separator. Maybe I was just doing it wrong?

Is there something like setting SWT GridLayout horizontalIndent? That would be wonderful.

I am working with JDK1.6.0_23.

+5
source share
4 answers

There are several ways to do this:

  • Establish the boundaries of each component: new EmptyBorder (0, 10, 0, 0).

  • Use GridBagLayoutand use Inset (0, 10, 0, 0)to enter the left side.

  • Use GridBagLayoutand check the main checkbox in the two columns, while the sub checkboxes are offset by placing them in the rightmost column.

  • Put your own checkbox icons that have some empty space added to their left edges.

and etc.

- GridBagLayout - , , . JGoodies , , GBL .

+2

JPanel . EmptyBorder .

+3

FormLayout, , 2 .

0

- SpringLayout .

0

All Articles