This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AbstractAction and Mnemonics

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me how I can setMnemonics and setAccelerator from a class that subclasses AbstractAction? Or if this is even possible?
For each JMenuItem I have an Action class that subclasses AbstractAction and I would like to encapsulate a lot of my JMenuItem stuff in this class rather than in the class where I construct my menu items.
Thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I figured out how to do this and thought I would share in case someone else wants to know how.

That is my custom Action class
Here is how I use it...

It's really that simple.
 
kyle amburn
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
Can't you pass the JMenuItem to the constructor of your AbstractAction class and then use this object to set each of the values you want?
Kyle
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kyle amburn:
Hi-
Can't you pass the JMenuItem to the constructor of your AbstractAction class and then use this object to set each of the values you want?
Kyle

Sure you could, but I like my method I posted a bit better. There is no need to do that. I don't like passing GUI objects around.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!