0

I have a JComboBox with numbers like:

JComboBox test;
String[] a = new String[5];
    for (int i = 0; i < 5; i++) {
        a[i]=i+1 + "";
    }
test = new JComboBox(a);

Now I want to spawn the number selected of JComboBoxes:

test.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String player =test.getSelectedItem();
            //Insert code here to create a variable number of Combo Boxes
        }
    });

The code looks messy. This is not what I am trying to do but it's a huge help for what I want.

Ignore the fact that numbers are as String within the code a parseInteger would do.

Thanks in advance.

Diego C Nascimento
  • 2,801
  • 1
  • 17
  • 23
Rafael Almeida
  • 5,142
  • 2
  • 20
  • 33

1 Answers1

0
public void actionPerformed(ActionEvent e) {
        int i = combo1.getSelectedIndex();
        combo2.setModel(models[i]);
    }

    @Override
    public void run() {
        JFrame f = new JFrame("ComboTest");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(this);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

Code Courtesy:-Dynamic JComboBoxes

Community
  • 1
  • 1
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61
  • That isn't what i want, I saw that article before posting. I want to spawn other JComboBoxes I dont want different models to the same Combo box – Rafael Almeida Sep 15 '13 at 18:39