How to remove actionPerformed methods in NetBeans
Asked Answered
P

4

21

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.

Publican answered 27/9, 2011 at 19:15 Comment(0)
D
63

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

Dilantin answered 27/9, 2011 at 19:20 Comment(1)
In Netbeans 7.2.1, I did not have a <none> option for some reason. Removing the value (making the field empty) did work though.Bullion
S
4

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.

Sackman answered 9/9, 2014 at 10:18 Comment(0)
S
1

In the latest version of netbeans click the button with the 3 periods [...] just to the right ov the combo box and a new control listing the handlers is displayed. Select the one to remove and press the [Remove] button.

Setzer answered 14/1, 2013 at 10:25 Comment(0)
H
-1

Identify your .java file, then close Netbeans and edit your file directly from a text editor.

Holotype answered 29/4, 2015 at 23:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.