我今天做了一个演讲,我真的写了老师的所作所为,但代码只是给了我一个错误说:
java: incompatible types: int cannot be converted javax.swing.ListSelectionModel
这是有问题的代码:
JList<String> list = new JList<>(listModel);
/*
...
*/
list.setSelectionModel(ListSelectionModel.SINGLE_SELECTION);
答案 0 :(得分:5)
我相信你的老师写道:
JList<String> list = new JList<>(listModel);
/*
...
*/
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//note how the methods name is supposed to end with Mode, not Model