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

Joz*_*ers 0 java swing compiler-errors jlist

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

java: incompatible types: int cannot be converted javax.swing.ListSelectionModel
Run Code Online (Sandbox Code Playgroud)

这是有问题的代码:

JList<String> list = new JList<>(listModel);
/*
...
*/
list.setSelectionModel(ListSelectionModel.SINGLE_SELECTION);
Run Code Online (Sandbox Code Playgroud)

Osk*_*ito 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
Run Code Online (Sandbox Code Playgroud)