tags:

views:

49

answers:

1

I have a little problem. I had some JComboBox to a JDialog but they won't show up ... Moreover I can select them (see the pic).

alt text

And here's my code :

for(int i = 0; i<11; i++)
    {
        JComboBox jC = new JComboBox(posteList);
        jC.setBounds(300, posY, 100, 20);
        jC.setSelectedIndex(0);
        this.add(jC);
        posY += 30;
    }

Have you got an idea to solve this problem ? Thanks !

+2  A: 

You're not supposed to call setBounds(), you need to use a layout to manage the components positions

Guillaume
Hum yes but I don't think that's the origin of my problem ... no ?
Pierre
The layout of your panel will call setBounds() after you did and displace the components. You HAVE to use a layout.
Guillaume
Ok, I'm coming from Apple dev and I never use layout, it's quite disturbed. Thanks
Pierre
Arguably, layouts are not the best part in Swing but you have to deal with them...
Guillaume
But I don't understand with when I write : JTextField j1L = new JTextField();j1L.setBounds(10, posY, 100, 20);this.add(j1L);It works fine ...
Pierre
I'm not sure what's going on, when you place your components using setBounds(), they stay there until a relayout is triggered. I guess the combobox behaves differently because it needs to pop out and because it's a composite control (a text field + a button + a list), so it needs its own layout.
Guillaume