• Post Reply Bookmark Topic Watch Topic
  • New Topic

Activate menu by pressing button on panel.  RSS feed

 
Enda Mc Laughlin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am trying to activate a menu at the top of a frame by pressing a button in java swing. I have no idea how to do it - for example pressing a button on a GUI would have the same effect as pressing alt-f to bring up a file menu at the top of a scree. Thanks for any help at all.....
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone else might have a suggestion for a cleaner solution...
You might be able to do something quick and dirty with java.awt.Robot .
Good Luck.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, this isn't a solution. More like a suggestion. But there should be an event of some sort that causes the menu to drop down like it does. I would search through the JMenu class files and see if you can't find that method and over-ride or invoke it when a button is pressed.
 
Enda Mc Laughlin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help. I eventually found it -
JMenu file = new JMenu ("File");
file.doClick(0);
The code above simulates a mouse click or the user pressing alf-f to access the file menu.
Cheers.
Enda.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!