在JList中怎样设置使其必选其一,即用Ctrl取消选择无效??

Joeym 2001-02-12 10:13:00
...全文
81 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aoao 2001-02-12
  • 打赏
  • 举报
回复
自己记录上一次的选择值,然后在selection 事件中判断被选item=0则恢复
masterz 2001-02-12
  • 打赏
  • 举报
回复
JList jList1 = new JList();
jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
skyyoung 2001-02-12
  • 打赏
  • 举报
回复
(Copy)
JList doesn't support scrolling directly. To create a scrolling list you make the JList the viewport view of a JScrollPane, e.g.

JScrollPane scrollPane = new JScrollPane(dataList);
// Or in two steps:
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().setView(dataList);

By default JList supports single selection, i.e. zero or one index can be selected. The selection state is actually managed by a separate delegate object, an implementation of ListSelectionModel however JList provides convenient properties for managing the selection.

String[] data = {"one", "two", "free", "four"};
JList dataList = new JList(data);

dataList.setSelectedIndex(1); // select "two"
dataList.getSelectedValue(); // returns "two"

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧