如何取消选中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);
答案 0 :(得分:0)
不确定这是否是您想要的,您可以使用t.setSelected(false)
。这将使JCheckBox取消选中。