Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enabling a disabled Menu Item  RSS feed

 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a JMenuItem and wish for it to start of disabled and based on an event for it to be enable(true). I can set the item to true but it never shows up as enabled.
I looked for a refresh but only found a repaint. The repaint did not seem to work. Please help me.
Thanks,
Kelly Harris
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't need to do a repaint using setEnabled(true). Are you sure your event is coded correctly? It would be easier to help if you post some of the code.
 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very straight forward code but it is thrown across multiple classes. I build the JMenuItem and then disable it. Add it to a JMenuBar. Along the lines a user can do a file->open that will trigger this item to be active. I would also like to use this with Copy/Cut/Paste under an edit menu.
I put together a little snippit of code that demonstrates what I am talking about.
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is your problem:

enable(true) needs to be changed to setEnabled(true)
 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Angela. I do not know why I used the Enable Method. So what does Enable do? From what I read it should have worked.
 
Angela Lamb
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The enable method is deprecated as of version 1.1 - that's why it no longer works correctly. It has been replaced by the setEnabled method.
 
Kelly Harris
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Angela, you are the best.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!