How to remove actionPerformed methods in NetBeans

2019-02-05 20:17发布

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.

4条回答
太酷不给撩
2楼-- · 2019-02-05 21:05

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

查看更多
Ridiculous、
3楼-- · 2019-02-05 21:09

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.

查看更多
混吃等死
4楼-- · 2019-02-05 21:14

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.

查看更多
走好不送
5楼-- · 2019-02-05 21:16

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

查看更多
登录 后发表回答