【发布时间】:2017-01-09 17:14:37
【问题描述】:
当我创建我的 JList 时,我可以使用 getSelectedValue() 打印出我在列表中选择的字符串。只要我更改列表中的内容,返回的所有内容都是空的。
创建列表时,我有这个:
matchList.setModel(new javax.swing.AbstractListModel<String>() {
String[] playerList = {"test"};
public int getSize() { return playerList.length; }
public String getElementAt(int i) { return playerList[i]; }
});
稍后我将 JList 更改为包含字符串数组:
matchList.setListData(Bracket.wr1);
数组中的所有内容都显示在 JList 中,但如果我尝试使用 getSelectedValue() 来获取正在显示的字符串,它只会返回 null。
我做错了什么?
【问题讨论】:
-
hm 所以唯一的问题是更改选项后没有选中项?