1

I want to add a window on clicking the menu item of a right click popupmenu in Java swing(seems like a simple task...but not getting)

I got it to partly work by

adding a custom menuitem in popupmenu
adding a window on right click

But this only partly works. Now I when I right click anywhere a window pops up, but the selected menu item in the popupmenu does not pop up the window. How can I get window on clicking my menu item? or is there an easier way to do this in java?

I know there are others ways of doing this (in code), but I would prefer to use Java swing

Has anyone ever done this before?

Thanks for your help

mKorbel
  • 109,525
  • 20
  • 134
  • 319

1 Answers1

2
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • i am done with adding the menu items...all i want to do now is....whenever i click on my menu item a window will get appear.. – nishita wadhawan Jan 24 '13 at 08:59
  • this is basic property of JPopup container, valid for JPopup and JComboBox, there no way without dirty hack, sure with important side effects, have to creating own popup window based on undecorated JDialog or JWindow – mKorbel Jan 24 '13 at 09:01
  • have look at [JCalendar](http://www.toedter.com/), one of the best custom popup window, – mKorbel Jan 24 '13 at 09:04
  • i want to open a new window on clicking the menu item..what is the possible solution to this problem ? right now window is opening whenever i right click my mouse...not when i click on menu item – nishita wadhawan Jan 31 '13 at 06:26
  • don't open a new window, use CardLayout instead – mKorbel Jan 31 '13 at 07:16
  • Thanks, but i actually want to get the right click location in that window and that window should appear whenever a user click on that custom menu item – nishita wadhawan Jan 31 '13 at 08:58
  • [example fired from JButton, there isn't any diff with event from JMenuItem](http://stackoverflow.com/a/8979275/714968), but create only one JDialog with defaultcloseoperation.hideonclose, reuse that for another action from JMenuItem – mKorbel Jan 31 '13 at 09:02