1

First, I'm sorry for my english, it's not my native language. I try to do my best

I have some problems with my display. I've a java.util.List of Panel with some elements already inside. I'd like to insert them into a JPanel at the creation of my JDialog. There are two JButton in my JDialog, 'add' and 'delete', wich, respectively add a new JPanel at the bottom of the JPanels and the other which delete the last JPanel added. My problem is that there is a large gap between two JPanel, regardless of the number of JPanel added and I don't know why... Two demonstrations pics :


my JDialog with 3 JPanel

my JDialog with more than 3 JPanel

My layouts are GridBagLayout and I'm using WindowBuilder with Eclipse Indigo. Here is now my code. I think the problem come from the value that I assign to anchor in the GridBagConstraints...
listChamps is the List of JPanel that I want to insert
panelListFile is the JPanel where listChamps' elements are inserted

for (int i = 0; i < listChamps.size (); ++i) {
            GridBagConstraints gbc_pan = new GridBagConstraints ();
            gbc_pan.gridwidth = 1;
            gbc_pan.fill = GridBagConstraints.HORIZONTAL;
            gbc_pan.anchor = GridBagConstraints.NORTH;
            gbc_pan.gridx = 0;
            gbc_pan.gridy = i;
            panelListFiles.add (listChamps.get (i), gbc_pan);
 }

Thanks you.

Carvallegro
  • 1,241
  • 4
  • 16
  • 24

2 Answers2

2

I using two ways and in both cases should be added a JPanel nested JComponents,

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • I just find out the solution ! The probleme came from the anchor value of my panelListFile GridBagConstraint. It was on Center instead of North.. But thank you for your answer, it will be helpful for other stuff – Carvallegro May 16 '12 at 08:04
1

You may use JPanel in JPanel by adding and rearranging their layout using different styles.

U.Kaya
  • 27
  • 3