我正在为我的java程序使用JComboBox,框的代码如下所示
JComboBox category = new JComboBox(cats);
category.addActionListener(this);
category.setActionCommand("combo");
category.setBounds(125,200,400,50);
add(category);其中cat是字符串数组。但是,即使我更改了选定的索引,getSelectedIndex()方法仍然返回0。请帮帮忙。
发布于 2016-01-13 14:27:04
你有没有试过这个:
String[] cats = new String[] {"meow1", "meow2"};
JComboBox<String> category = new JComboBox<>(cats);发布于 2016-01-13 19:38:43
你试过这个吗?
JComboBox category = new JComboBox();
category.addActionListener(this);
category.setActionCommand("combo");
category.setBounds(125,200,400,50);
add(category);
category.setModel(new DefaultComboBoxModel<>(cats));https://stackoverflow.com/questions/34759236
复制相似问题