无法将复选框添加到JList [英] Cannot add checkbox to the JList
本文介绍了无法将复选框添加到JList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对编程很陌生,不能将JCheckbox
添加到JList
.没有错误,但未显示任何内容.
I'm very new to programming, and I can't add JCheckbox
to the JList
. There is no error but nothing is displayed.
JFrame f=new JFrame();
String[] labels={"a","b","c","d","e"};
JCheckBox[] ch=new JCheckBox[labels.length];
JList list=new JList();
for (int i = 0; i < labels.length; i++) {
ch[i]=new JCheckBox("CheckBox"+i);
list.add(ch[i]);
}
JScrollPane pane=new JScrollPane(list);
f.add(pane);
f.setVisible(true);
推荐答案
JList
渲染器可以绘制一个复选框,但是JList
不支持单元格编辑器.而是考虑一个单列JTable
.默认的渲染器&对于示例,类型为Boolean.class
的列的编辑器是JCheckBox
.
A JList
renderer can draw a checkbox, but JList
does not support a cell editor. Instead, consider a one-column JTable
. The default renderer & editor for a column of type Boolean.class
is a JCheckBox
, for example.
这篇关于无法将复选框添加到JList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文