简体   繁体   中英

NetBeans remove automatically generated action listener in design view

I'm using NetBeans design view. I added an action listener to a JMenuItem , which I want to remove. I seem unable to do it, because the generated code is in the grey area and the IDE won't let me edit it. 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

But I don't think you should.

Click on the JMenuItem, go to Properties pane.

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.

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. This will remove the code completely.

Select Design view, then find your JMenuItem in the Navigator pane. It is located by default on the left. If it is not present, select in the menu:

Window => Navigating => Navigator

or, as alternative click Ctrl+7.
When you find your JMenuItem in the Navigator pane, select it, right click and choose Delete .


UPDATE

Of course, by doing the above actions you'll get rid of JMenuItem itself.
If you wanted to get rid of action listener itself, then choose <none> for the desired action as @nitgeek suggested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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