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.
将JButton添加到内容窗格时,我们可以通过双击按钮或右键单击 - >事件 - >操作 - > actionPerformed来设置操作。让我们设置一些事情。然后我们需要删除该函数。通过删除我们在buttton的actionPerformed中编写的代码,可以轻松完成。但问题是,该按钮的actionPerformed方法仍然存在,即使它不再使用而且不需要。
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.
如何删除?我得到了JButton的一个例子。其他组件的动作方法是这样的。
4 个解决方案
#1
52
Go to your JButton properties, Choose "Events", actionPerformed and choose "none" from the adjacent combobox. Your source code is cleaned!
转到您的JButton属性,选择“Events”,actionPerformed并从相邻的组合框中选择“none”。您的源代码已清除!
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:
最新版本的Netbeans(如7.3)不提供“none”作为选项,但允许您通过删除方法名称或按1,2和3按钮来删除actionPerformed方法:
#2
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.
如果操作注册的按钮不再出现在表单中(这在我用先前的备份手动替换.form文件后发生在我身上),那么您将无法执行Costis Aivalis的解决方案。在这种情况下,您可以使用另一个文本编辑器打开.java文件并删除其中的事件处理程序。
#3
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.
在最新版本的netbeans中,单击组合框右侧的3个句点[...]按钮,将显示列出处理程序的新控件。选择要删除的一个,然后按[删除]按钮。
#4
-1
Identify your .java file, then close Netbeans and edit your file directly from a text editor.
识别.java文件,然后关闭Netbeans并直接从文本编辑器编辑文件。
#1
52
Go to your JButton properties, Choose "Events", actionPerformed and choose "none" from the adjacent combobox. Your source code is cleaned!
转到您的JButton属性,选择“Events”,actionPerformed并从相邻的组合框中选择“none”。您的源代码已清除!
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:
最新版本的Netbeans(如7.3)不提供“none”作为选项,但允许您通过删除方法名称或按1,2和3按钮来删除actionPerformed方法:
#2
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.
如果操作注册的按钮不再出现在表单中(这在我用先前的备份手动替换.form文件后发生在我身上),那么您将无法执行Costis Aivalis的解决方案。在这种情况下,您可以使用另一个文本编辑器打开.java文件并删除其中的事件处理程序。
#3
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.
在最新版本的netbeans中,单击组合框右侧的3个句点[...]按钮,将显示列出处理程序的新控件。选择要删除的一个,然后按[删除]按钮。
#4
-1
Identify your .java file, then close Netbeans and edit your file directly from a text editor.
识别.java文件,然后关闭Netbeans并直接从文本编辑器编辑文件。