简体   繁体   English

NetBeans在设计视图中删除自动生成的动作侦听器

[英]NetBeans remove automatically generated action listener in design view

I'm using NetBeans design view. 我正在使用NetBeans设计视图。 I added an action listener to a JMenuItem , which I want to remove. 我向JMenuItem添加了一个动作监听器,我想删除它。 I seem unable to do it, because the generated code is in the grey area and the IDE won't let me edit it. 我似乎无法做到这一点,因为生成的代码在灰色区域,IDE将不允许我编辑它。 I can't remove it through the properties window either. 我无法通过属性窗口删除它。 What do I do? 我该怎么办?

You can make changes to guarded code see here http://wiki.netbeans.org/FaqFormEditingGuardedBlocks 您可以对受保护的代码进行更改,请参见http://wiki.netbeans.org/FaqFormEditingGuardedBlocks

But I don't think you should. 但我不认为你应该这样做。

Click on the JMenuItem, go to Properties pane. 单击JMenuItem,转到“属性”窗格。

In Properties pane go to Events tab and remove the action listener from there. 在“属性”窗格中,转到“事件”选项卡,然后从中删除操作侦听器。 If you give nothing there, it will show "<none>" as the event listener. 如果你什么也没有,那么它将显示"<none>"作为事件监听器。

Now the action listener function will not be called, although the code will still be there. 现在不会调用动作侦听器函数,尽管代码仍然存在。

But, if those dead lines of code are bothering you, then you can either comment them, or remove the JMenuItem and add again. 但是,如果那些死代码的代码困扰着你,那么你可以对它们进行评论,或者删除JMenuItem并再次添加。 This will remove the code completely. 这将完全删除代码。

Select Design view, then find your JMenuItem in the Navigator pane. 选择“设计”视图,然后在“ 导航器”窗格中找到JMenuItem。 It is located by default on the left. 它默认位于左侧。 If it is not present, select in the menu: 如果不存在,请在菜单中选择:

Window => Navigating => Navigator Window => Navigating => Navigator

or, as alternative click Ctrl+7. 或者,作为替代方法,单击Ctrl + 7。
When you find your JMenuItem in the Navigator pane, select it, right click and choose Delete . 在“导航器”窗格中找到JMenuItem时,选择它,右键单击并选择“ 删除”


UPDATE UPDATE

Of course, by doing the above actions you'll get rid of JMenuItem itself. 当然,通过执行上述操作,您将摆脱JMenuItem本身。
If you wanted to get rid of action listener itself, then choose <none> for the desired action as @nitgeek suggested. 如果你想摆脱动作监听器本身,那么选择<none>作为@nitgeek建议的所需动作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM