gpt4 book ai didi

java - 使用代码在 JList 中选择项目

转载 作者:行者123 更新时间:2023-11-30 06:09:09 26 4
gpt4 key购买 nike

我希望能够编写一个手动选择JList中的项目的语句,例如:

JList myList = new JList(items);
myList.selectValueAt(index);

最佳答案

JList 的文档:

The selection state of a JList is managed by another separate model, an instance of ListSelectionModel. JList is initialized with a selection model on construction, and also contains methods to query or set this selection model. Additionally, JList provides convenient methods for easily managing the selection. These methods, such as setSelectedIndex and getSelectedValue, are cover methods that take care of the details of interacting with the selection model. By default, JList's selection model is configured to allow any combination of items to be selected at a time; selection mode MULTIPLE_INTERVAL_SELECTION. The selection mode can be changed on the selection model directly, or via JList's cover method. Responsibility for updating the selection model in response to user gestures lies with the list's ListUI.

在你的情况下:

myList.setSelectionIndex(index);

关于java - 使用代码在 JList 中选择项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38518934/

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