我的JList模型方法给了我一个错误

时间:2017-05-03 21:26:51

标签: java swing compiler-errors jlist

我今天做了一个演讲,我真的写了老师的所作所为,但代码只是给了我一个错误说:

java: incompatible types: int cannot be converted javax.swing.ListSelectionModel

这是有问题的代码:

JList<String> list = new JList<>(listModel);
/*
...
*/
list.setSelectionModel(ListSelectionModel.SINGLE_SELECTION);

1 个答案:

答案 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