JPopupMenu loses focus

J

javadev

I have a strange problem involving multiple JPopupMenus.

I have a JPanel from which I open a JPopupMenu. From this menu I open
another JPopupMenu. The problem is for any mouseClicked event anywhere
on the 2nd popup menu, the menu loses focus and disappears behind the
parent JFrame.


Is this something common and is there a workaround to it? Or is there
something wrong I am doing?


Following is the code:


// firstMenu is the JPopupMenu created from the JPanel


openButton = new JButton("Open Popup");
openButton.setActionCommand("open");
openButton.addActionListener(new ButtonClickListener());
firstMenu.add(openButton);


Here is the code for the ButtonClickListener:


class ButtonClickListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("open"))
{
JPopupMenu secondMenu = new JPopupMenu();
// add components to the menu
secondMenu.show();
}
}



}


Any help would be greatly appreciated.

Thanks
SS
 
C

Christian Kaufhold

javadev said:
I have a JPanel from which I open a JPopupMenu. From this menu I open
another JPopupMenu. The problem is for any mouseClicked event anywhere
on the 2nd popup menu, the menu loses focus and disappears behind the
parent JFrame.


set the JPopupMenu "invoker", i.e. by using show(Component, ...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top