简体   繁体   English

取消选中 JCheckBox

[英]Uncheck the JCheckBox

How can I uncheck the JCheckBox ?如何取消选中JCheckBox

I am making a GUI in which I want to uncheck the selected check box after click on the "Add" button.我正在制作一个 GUI,我想在单击“添加”按钮后取消选中选定的复选框。 What I am doing when I select the check box and display name will be add in to array list Panel.Arr .当我选择复选框时我在做什么,显示名称将添加到数组列表Panel.Arr After click on Add button selected check boxes added in to the "List of the image to be imported panel".单击添加按钮后,选中添加到“要导入的图像列表面板”中的复选框。

I want that when selected check box add in to "Image to be imported panel", the selected check box becomes unchecked/disabled.我想要在选中复选框时添加到“要导入的面板映像”,所选复选框变为未选中/禁用。 So that user will not select again once its add in to the "Image to be imported panel"这样用户一旦添加到“要导入的图像面板”就不会再次选择

I am pasting the snapshot of my GUI so that you can understand easily.我正在粘贴我的 GUI 快照,以便您可以轻松理解。

在此处输入图片说明

and I am also pasting my checkbox display code and add button code //checkbox display code我还粘贴了我的复选框显示代码并添加了按钮代码 //复选框显示代码

{       
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
}

//Add button code //添加按钮代码

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);

Not sure if this is what you want, you can use t.setSelected(false) .不确定这是否是您想要的,您可以使用t.setSelected(false) That'll make the JCheckBox unchecked.这将使 JCheckBox 取消选中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM