0

I have two RadioButtons and this is the code that keeps getting set for them:

jRadioButton6.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jRadioButton6MouseClicked(evt);
        }
    }

I modified in an text editor the method to this:

   jRadioButton6.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            jRadioButton6MouseClicked();

        }
    }

It appears making modifications to the interface triggers this behavior.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alexandru Cimpanu
  • 1,029
  • 2
  • 14
  • 38
  • Did you use Netbeans to change it or a different text editor? Did you refresh everything in Netbeans so it knowns the file has changed, or restarted the thing / recompiled your code? – Philipp Gayret Jun 14 '14 at 17:49
  • I have a backup version of my code which contains the modifications and I use Beyond Compare to return to a workable version or in this case to restore the methods. The backup version is in a different folder and I saved the changes restarted NedBeans, sometimes it works to run the code, I haven't been able figure out what causes this. – Alexandru Cimpanu Jun 14 '14 at 17:54
  • It appears modifying the interface triggers the edit. – Alexandru Cimpanu Jun 14 '14 at 17:57
  • Do not add a `MouseListener`, but - using java 8: `jRadioButton6.addItemListener(e -> jRadioButtonMouseClicked());`. That maybe does not need templating. – Joop Eggen Jun 14 '14 at 18:02
  • @Alexandru Cimpanu use ActionListener or ItemListener for JRadioButton, without recrusive whatever to MouseListener – mKorbel Jun 14 '14 at 18:17
  • Another way that I found is to play with the design of the components until you are satisfied with the appearance and then modify the code with other editors. And always have a backup... – Alexandru Cimpanu Jun 14 '14 at 20:31

1 Answers1

0

I was trying to modify the auto-generated code. There is even a warning at the start of the code:

    /**
    * This method is called from within the constructor to initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is always
    * regenerated by the Form Editor.
    */

So in the Design view I should have selected the jRadioButton and under the Events I should have selected itemStateChanged and set the function that I wanted to be called for that event.

I did a compare of my mistake in the left and the solution on the right: Compare

Alexandru Cimpanu
  • 1,029
  • 2
  • 14
  • 38