Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to add popup menu on button  RSS feed

 
Karan Galhotra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends

i am new to swings and stucked in a issue.

i want to add a popmenu on button.(Like "Back" button present in internet explorer window)

Thkx in advance
 
Vanessa Astle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just create a ButtonListener class that implements the ActionListener class. Then create an actionPerformed(ActionEvent e) method, and within that method instantiate a JDialog, or whatever kind of popup you were wanting. That way you can attach a ButtonListener object to a button, and each time the button is pressed the actionPerformed(ActionEvent e) method will be called.
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karen,

The following event handler will display a popup menu on whatever component generated the event, in this case a JButton. Note that the menu will be located in the upper left hand corner of the component (Thats the 0,0 parameters to the show()), you can change that to wherever you want.

Although this example creates the JPopupMenu and JMenuItems in the handler, usually you would create your popup menu some other time, add event handlers to the JMenuItems, etc... and just display it in the event handler.

Hope that helps,

Darrin
 
Karan Galhotra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THkx Darrin & Vanessa
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!