Moving JFrame to display JCombobox correctly

I programmed a JFrame that JPanel adds, and this adds my JCombobox. My problem is that JCombobox will not display directly until I resize my frame.

Here is my code:

    /* JFrame */
    frame = new JFrame("Frame");
    frame.setBounds(0, 0, 900, 800);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    /* JPanels */
    panel = new JPanel();
    panel.setBounds(frame.getBounds());
    panel.setVisible(true);
    panel.setLayout(null);
    panel.addMouseListener(m);

    /* JComboBox */
    String comboBoxListe[] = { "1", "2", "3" };
    JComboBox chooser = new JComboBox(comboBoxListe);
    chooser.setSize(200, 25);
    chooser.setLocation(30, 30);
    chooser.setVisible(true);

    panel.add(chooser);
    frame.add(panel);

Can anyone understand what I did wrong? Thanks for the help:)

+4
source share
1 answer

JFrame was made visible before the combo box was added

frame.setVisible(true);

Make sure this appears after adding the component.

Swing was designed for layout managers to use - use one here

+2
source

All Articles