I encoutered a strange behaviour of handling mouse position by Swing when maximizing JFrame:
When I execute this very simple code…
public class Test {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("File");
menu.add(new JMenuItem("New"));
menubar.add(menu);
frame.setJMenuBar(menubar);
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
… I can normally click File (first click – press,release) -> New (second click). But when I maximize JFrame and click on File – context menu disappears on mouse release immediately.
Moreover when I hold mouse button – to prevent disappearance – I must move my mouse much further to focus on New item.

The red dot represents area (more or less) where I must move my mouse to focus on New after pressing File and holding mouse button.
I’ve observed the same behaviour when using “right-click context menu” for example when right clicking on chart from JFreeChart.
I thought it was JDK problem because I used Oracle’s JDK, but after installing OpenJDK I have the same results.
Did somebody observe this strange behaviour? Or am I missing something obvious?
I use:
- 1.7.0_147-icedtea (or 1.7.0_04 for java-7-oracle)
- OpenJDK Runtime Environment (IcedTea7 2.0) (7~b147-2.0-0ubuntu0.11.10.1)
- OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)
- Linux Mint 12 (lisa) GNOME 3.2.1
Yes – this is a bug in JDK7 as @nIcE cOw mentioned.
I’ve installed JDK6 and I couldn’t reproduce this bug.