gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:49:18 25 4
gpt4 key购买 nike

我今天有一个讲座,我确实写了老师所做的事情,但代码只是给了我一个错误:

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

这是有错误的代码:

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

最佳答案

我相信你的老师写道:

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

//note how the methods name is supposed to end with Mode, not Model

关于java - 我的 JList 模型方法给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43770290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com