如何获取JPanel中被选中的JCheckBox
initComponents();PermissionCrudpc=newPermissionCrud();ArrayListlist=pc.Query();Iterat...
initComponents();
PermissionCrud pc = new PermissionCrud();
ArrayList list = pc.Query();
Iterator it = list.iterator();
QxPanel.setPreferredSize(new Dimension(170,300));
QxPanel.setLayout(new GridLayout(list.size()/1+1, 1));
QxPanel.setBorder(BorderFactory.createTitledBorder("dddddd"));
for(int i =0;i<list.size();i++){
String name = (String)it.next();
QxPanel.add(new JCheckBox(name)); 展开
PermissionCrud pc = new PermissionCrud();
ArrayList list = pc.Query();
Iterator it = list.iterator();
QxPanel.setPreferredSize(new Dimension(170,300));
QxPanel.setLayout(new GridLayout(list.size()/1+1, 1));
QxPanel.setBorder(BorderFactory.createTitledBorder("dddddd"));
for(int i =0;i<list.size();i++){
String name = (String)it.next();
QxPanel.add(new JCheckBox(name)); 展开
2个回答
2013-01-31
展开全部
容器组件,有方法 getComponents() 得到 Component[]。再判断是否JCheckBox,即可以取得Checked状态
展开全部
public List<JCheckBox> getSelectedBox(){
List<JCheckBox> list = new ArrayList<JCheckBox>();
Component[] comps = panel.getComponents();
if(comps.length > 0){
for(int i=0; i<comps.length; i++){
Component comp = comps[i];
if(comp instanceof JCheckBox){
JCheckBox box = (JCheckBox)comp;
if(box.isSelected()){
list.add(box);
}
}
}
return list;
}
List<JCheckBox> list = new ArrayList<JCheckBox>();
Component[] comps = panel.getComponents();
if(comps.length > 0){
for(int i=0; i<comps.length; i++){
Component comp = comps[i];
if(comp instanceof JCheckBox){
JCheckBox box = (JCheckBox)comp;
if(box.isSelected()){
list.add(box);
}
}
}
return list;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询