mardi 25 octobre 2022

How to clear JCheckBox text which was added to TextArea when unselected

I am creating a programme which displays the value of JCheckBoxes whenever one or more are selected in a textarea I am trying to make it so when the checkbox is unselcted that specific text only dissapears for example.

Java : check c+: check

TextArea Display Java c+

Java : uncheck c+: check

TextArea Display c+


     
     cBox1 = new JCheckBox("Java");
     panelCheckBoxes.add(cBox1);
     cBox1.addActionListener(this);
     
     cBox2 = new JCheckBox("C+");
     panelCheckBoxes.add(cBox2);
     cBox2.addActionListener(this);
public void actionPerformed(ActionEvent e) {    
        
     {
             if (e.getSource() instanceof JCheckBox) {

                    JCheckBox cb = (JCheckBox)e.getSource();
                    String text = cb.getText();
                    
                    boolean isNotSelected = !cb.isSelected();
                
                     if(cb.isSelected()) {
                             txtrShow.append(text + "\n");
                     }else if(isNotSelected == true)
                         txtrShow.replaceSelection("");
                }
             
        
             }



Aucun commentaire:

Enregistrer un commentaire