Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove actionPerformed methods in NetBeans

Tags:

When a JButton is added to a content pane, we can set an action by double clicking the button or Right click->Event->Action->actionPerformed.Let say, we set somthing to happen. Then we need to remove that function.It can be done easily by deleting the code we wrote in that buttton's actionPerformed. But the problem is, that button's actionPerformed method is still there even though it is not used any more and not needed.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                             //no function here.. but this  code is still remaining. need to remove this code part as well } 

How can it be removed? I got the JButton for an example. Other components'action methods are like this.

like image 783
Débora Avatar asked Sep 27 '11 19:09

Débora


People also ask

How do I delete an action listener?

Event listeners can also be removed by passing an AbortSignal to an addEventListener() and then later calling abort() on the controller owning the signal.


2 Answers

Go to your JButton properties, Choose "Events", actionPerformed and choose "none" from the adjacent combobox. Your source code is cleaned!

Netbeans Properties

Recent versions of Netbeans like 7.3, do not offer "none" as an option, but allow you to delete the actionPerformed method by deleting the name of the method or by pressing 1, 2 and 3 buttons:

enter image description here

like image 67
Costis Aivalis Avatar answered Sep 20 '22 19:09

Costis Aivalis


If the button that the action was registered to is no longer in the form (this happened to me after I manually replaced the .form file with a previous backup) then you wont be able to do Costis Aivalis's solution. In this case you can open the .java file with another text editor and delete the event handler there.

like image 26
Toby 1 Kenobi Avatar answered Sep 19 '22 19:09

Toby 1 Kenobi