Hi, folks!
I've a JMenuBar, consisting of two JMenus.
The first JMenu is called, "File," and has one JMenuItem called, "X."
When the user clicks X, he's presented with a JOptionPane that says,
for example, "You've clicked X," and offers and OK button to close the
JOptionPane.
The second JMenu is called, "Edit," and has one JMenuItem called, "Y."
As with X, when the user clicks Y, he's presented with a JOptionPane
saying that he's click Y.
These are loaded into a JMenuBar and the menu is displayed on top of a
JPanel that shows some graphics.
I'm seeing a frustrating problem.
If the user clicks File->X, and then closes the subsequent
JOptionsPane, and then clicks File again, he will be presented with
the menu holding the item, "X." As soon as the user moves the mouse
down to click X, however, the menu disappears. If he then moves the
mouse back up to, "File," the menu automatically appears even without
clicking. This time, the menu stays visible when the mouse is moved
down to the X item, thus allowing X to be clicked again.
The same happens if the user clicks Edit->Y and closes the
JOptionsPane. If he then clicks Edit, then as soon as the mouse is
moved down to the Y, the menu disappears.
If, however, the user clicks File->X, and closes the subsequent
JOptionPane, and then moves the mouse over the Edit menu, then the
menu appears and it doesn't disappear when the mouse is brought over
the Y item.
Similarly, if the user clicks Edit->Y, and closes the subsequent
JOptionPane, then there is no problem clicking File->X.
Anyone seen anything like this?
I have other JMenus that don't open new windows (or JOptionPanes) and
these all work fine.
Help appreciated,
.ed
www.EdmundKirwan.com
Sample set-up code:
=============================================================
JMenuBar menuBar = new JMenuBar();
// Build the file fileMenu
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
fileMenu.getAccessibleContext().setAccessibleDescription("Load
files");
// File menu items: X
JMenuItem loadMasterMenuItem = new JMenuItem("X", KeyEvent.VK_L);
loadMasterMenuItem.setAccelerator(KeyStroke.
getKeyStroke(KeyEvent.VK_1,
ActionEvent.CTRL_MASK));
loadMasterMenuItem.getAccessibleContext().
setAccessibleDescription("This does X");
loadMasterMenuItem.addActionListener(menuListener);
fileMenu.add(loadMasterMenuItem);
menuBar.add(fileMenu);
============================================================
And in the mouselistener referenced above:
/**
* Services a menu-related mouse-click.
*
* @param event mouse-click event to be serviced
*/
public void actionPerformed(ActionEvent event) {
JMenuItem source = (JMenuItem)(event.getSource());
// Service requests to load a new master directory
if (source.getText().equals("X")) {
processNewDirectory();
return;
}
}
VisionSet - 31 May 2004 23:56 GMT
> As soon as the user moves the mouse
> down to click X, however, the menu disappears.
It's a bug
search bug parade keywords 'joptionpane' 'jmenu'
It's hit #1
You found my earlier post on c.l.j.gui
All the suggested workarounds on bug parade fail for me.
And it only has 16 votes.
Please post any solutions or alternative approaches you find here.
I thought it was to do with the menu popping outside of the parents bounds.
But it isn't. It is definitely connected with the JOptionPane.
And I bet it is event related. Maybe try and fire an extra event from the
JoptionPane?
--
Mike W