Find a tutorial on changing the JMenuBar
I have made a GUI and the JMenubar and that works great. I am looking for a tutorial to teach me how to cancel out something. The simplest example I can think of if you go to edit and paste is grayed out. But you cut something and it works great. That is want to learn.
I have tried creating two bars, and just simply calling frame.setJMenuBar(bar1 or bar 2). However, the second bar is always blank.
If someone has a good resource let me know. Google didn't help me on this one.
Thank you,
Kyle
Re: Find a tutorial on changing the JMenuBar
Cancel out sense, you are talking about undo-redo functionality? I am not clear with what you are saying.
Re: Find a tutorial on changing the JMenuBar
Seems you're looking for setEnabled(true/false). If that's not it, you may find what you want here: How to Use Menus (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
And since this is a Swing topic, I'm moving the thread to the appropriate forum.
db
Re: Find a tutorial on changing the JMenuBar
How to Use Menus and How to Use Actions in Oracle's Tutorial are worth reading.
The basic idea is that you create a menu item based on an instance of Action. These action instances can be disabled (they have a method for that) and when they are disabled the corresponding menu item is greyed out. In the example you mention you might check the contents of the clipboard every time you change it with a "cut" and update the paste action (enable/disable) based on whether the clipboard has some content.
Re: Find a tutorial on changing the JMenuBar
Thank you. The reading helped.
For those people that are trying to do the same thing, I clicked on a series of links that I found myself here: Enabling And Disabling A MenuItem - Java | Dream.In.Code