views:

30

answers:

2

I'm trying to insert some spacers into a layout on JPanel. I've got 3 buttons and I'd like to put something similar to Box.createRigidArea(new Dimension(10, 0)) between them. Netbeans 6.9.1 doesn't seem to have an option to create them - is that true? Is there some workaround?

+1  A: 

Simple work around would be to add a JPanel with a custom preferred size.

camickr
+1  A: 

Another approach is to set the JPanel to use BoxLayout and modify a button's Pre- or Post-Adding code to include the desired Component:

this.add(Box.createVerticalStrut(10));

The generated code will look like this:

jButton1.setText("jButton1");
this.add(Box.createVerticalStrut(10));
add(jButton1);
this.add(Box.createVerticalStrut(10));

You'll also need to import javax.swing.Box.

trashgod