【发布时间】:2013-10-08 05:37:38
【问题描述】:
如何取消选中JCheckBox?
我正在制作一个 GUI,我想在单击“添加”按钮后取消选中选中的复选框。当我选中复选框时我在做什么,显示名称将添加到数组列表Panel.Arr。单击添加按钮后,选中的复选框添加到“要导入的图像列表面板”中。
我希望在选定的复选框时添加到“要导入的面板映像”,所选复选框变为未选中/禁用。这样用户就不会在添加到“要导入的图像面板”后再次选择
我正在粘贴我的 GUI 快照,以便您轻松理解。
我还粘贴了我的复选框显示代码并添加按钮代码 //复选框显示代码
{
int space=30;
// create a check button (for selection) for each target resource
for (int i=0; i < images.size(); i++) {
ResourceListObject resource = images.get(i);
// create the radio button for this target
t = new JCheckBox(resource.getName() + ", " + resource.getOID());
t.addActionListener(this);
t.setBackground(SystemColor.menu);
t.setName(""+i);
t.setActionCommand(resource.getName()+"_"+resource.getOID());
t.setBounds(13, space,355, 23);
t.setVisible(true);
panel.add(t);
space=space+25;
// add the virtual target to the target group, then to the panel
}
//添加按钮代码
JButton btnNewButton = new JButton("Add >>");
btnNewButton.setBounds(437, 312, 100, 23);
btnNewButton.addActionListener(new ActionListener() {
@SuppressWarnings("static-access")
public void actionPerformed(ActionEvent arg0)
{
Volume_ID_Image_tmp = restEngine.getimageContent(Panel.Arr);
try {
@SuppressWarnings("unused")
ImportImagePanel jsonobj = new ImportImagePanel(Volume_ID_Image_tmp,panel_1,"add");
} catch (IOException e) {
e.printStackTrace();
}
Volume_ID_Image.addAll(Volume_ID_Image_tmp);
Volume_ID_Image_tmp.clear();
}
});
frmToolToMigrate.getContentPane().add(btnNewButton);
【问题讨论】:
-
您应该将
JCheckBoxs 放在某种列表中,然后在列表中运行并更新它们的选定状态 -
@Andrew Thompson 我对 java 有点熟悉。如果您能详细解释一下,我会很棒。
-
你的意思是@MadProgrammer 的评论;)
-
@AndrewThompson 哦,不,他们没有;)
-
@MadProgrammer 好吧,我真的只是在猜测,考虑到他们对我编写代码的呼吁将“置若罔闻”。 :P
标签: java swing checkbox jcheckbox