Using Swing, what is the best way to indent some components underneath a checkbox or radio button? I need to make something in the style of Firefox 3.6's Options->Privacy dialog where some checkboxes are indented under a "main" checkbox. I can use any of the standard AWT/Swing layout's including GroupLayout. I also have JGoodies FormLayout available to me. I tried using setLeadingColumn offset in FormLayout at first, but it seemed like it was not going to work well unless I was indenting under a Separator. Maybe I was just doing it wrong?
Is there anything like SWT GridLayout's horizontalIndent setting? That would be perfect.
I am working with JDK1.6.0_23.
preguntado el 08 de enero de 11 a las 19:01
Hay varias maneras de hacer esto:
Set each components border to:
new EmptyBorder (0, 10, 0, 0).
GridBagLayouty usa un
Inset (0, 10, 0, 0)to pad the left side.
GridBagLayoutand have the main checkbox span two columns, whilst the sub checkboxes are offset by placing them in the rightmost column.
Supply custom checkbox icons that have some empty space added to their left hand edges.
My advice would be to learn the
GridBagLayout - it is somewhat unwieldy to use but it does give you pretty much all the layout power you could want. The JGoodies stuff is useful for when you want particular automatic column sizing behaviour that GBL won't give you without some additional code on your part.
Create a JPanel for the sub components. Then you can add an EmptyBorder to the panel with the required indentation.
You should be able to accomplish this just fine with FormLayout, just add another column for the sub items, and have the main item span 2 columns.
Another option is to use SpringLayout and add padding.