This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

JMenuItem enable

 
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have several JMenuItems with associated actions.
First, actions are disabled and so are the menu items.
When the status of the actions changes and they become enabled, the menu items are still disabled.
How can I force a JMenuItem to check if its action is enabled or not, update itself and displays right ?
 
gardener
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... Take a look at the example code below and see if it works...

 
huguette santos
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your answer.
By looking at your code I understand that calling Action.setEnabled() affects also the JMenuItem.
Im my code I assumed that JMenuItem invokes Action.isEnabled before JMenuItem is drawn ... and that is not true.
Now I added a MenuListener to my menu that checks if the actions are enabled/disabled and sets the JMenuItems.
It seems to work, but I wonder if the MenuListener is always invoked before the Menu is drawn ?
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!