dimanche 29 avril 2018

add dynamic checkbox in java windowbuilder

I want to add a dynamic checkbox after selecting an item in combo box. I am working on eclipse and design my frame on window builder.

    final JComboBox<String> comboBox = new JComboBox<String>();
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String typeName = comboBox.getSelectedItem().toString();
            for (int i = 0; i < SqlQuery.getCoursesName(typeName).size(); i++) {
                JCheckBox c = new JCheckBox(SqlQuery.getCoursesName(typeName).get(i));
                c.setVisible(true);
                coursePanel.add(c);

                frame.repaint();
                frame.validate();

                System.out.println(c.getText());
            }
        }
    });
    comboBox.setBounds(208, 221, 91, 20);
    frame.getContentPane().add(comboBox);

Why the frame does'nt show the checkbox? Thank you.




Aucun commentaire:

Enregistrer un commentaire