繁体   English   中英

JComboBox将开始索引设置为“ 1”

[英]JComboBox set start index to “1”

是否有一种简单的方法将JComboBox的起始索引设置为“ 1”或“ 2”? 如果启动应用程序,索引通常设置为“ 0”,但我想以索引“ 1”开头。

编辑:

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()));
});

使用JComboBox#setSelectedIndex(int anIndex)

选择索引为anIndex的项目。

要选择列表中的项目,请使用JComboBox#setSelectedItem(Object anObject)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM