vendredi 29 mai 2015

JComboBox set start index to "1"

Is there an easy way to set the start index of an JComboBox to "1" or "2"? If you start your application the index is normal set to "0" but I want to start with index "1" instead.

Edit:

JComboBox variableBox_1 = new JComboBox();
        for (int i = 0; i < dataModel.getVariableNames().size(); i++) {
            variableBox_1.addItem(dataModel.getVariableNames().get(i));
        }
        JPanel comBoxPanel1 = new JPanel(new BorderLayout());
        JLabel comBoxLabel1 = new JLabel("X:");
        comBoxPanel1.add(variableBox_1, BorderLayout.CENTER);
        comBoxPanel1.add(comBoxLabel1, BorderLayout.WEST);
        optionPanel.add(comBoxPanel1);
        variableBox_1.addActionListener((ActionEvent e) -> {
            sp.setVariableNumberX(variableBox_1.getSelectedIndex());
            hg1.setVariableNumber(variableBox_1.getSelectedIndex());
            sp.setXvariableText(dataModel.getVariableNames().get(variableBox_1.getSelectedIndex()));
        });

Aucun commentaire:

Enregistrer un commentaire