Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I neatly indent some components using Java Swing layouts

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.

like image 243
Jason Avatar asked Jan 08 '11 19:01

Jason


People also ask

Which layout allows you to put components in five regions?

A BorderLayout places components in up to five areas: top, bottom, left, right, and center. All extra space is placed in the center area.

How do I set absolute layout in Java?

For this go to app > res > layout > activity_main. xml file and change the Constraint Layout to Absolute Layout and add TextViews.

What is the best layout in Java?

Most common layouts: GridBagLayout - excellent when many components involved. BoxLayout (and associated Box class) - "glue" and "struts" (defined in Box , not BoxLayout ), combined with proper alignment and equalization of sizes, produce results pleasing to the eye. BorderLayout - often suitable for a top level ...


1 Answers

Create a JPanel for the sub components. Then you can add an EmptyBorder to the panel with the required indentation.

like image 193
camickr Avatar answered Sep 30 '22 05:09

camickr