Swing JMenu acting strange

I have recently started making a minesweeper-like game in java with swing (using eclipse WindowBuilder), and in the app there is an ordinary JFrame with a JMenu with options in it. It works as it should until window is resized. Then, when I click on the menu to show it, it is shown only until I release the mouse button, and then it dissapears as if I clicked soewhere else. But when I access the menu by keyboard shortcut, it works properly. Does anyone know where might the problem be? Code of menu:

    JMenu mnHelp = new JMenu( "Help" );
    mnHelp.setMnemonic( 'h' );
    menuBar.add( mnHelp );

    JMenuItem mntmControls = new JMenuItem( "Controls" );
    mntmControls.setMnemonic( 'c' );
    mntmControls.setIcon( new ImageIcon( Main.class
            .getResource( "/org/img/menu-help.png" ) ) );
    mnHelp.add( mntmControls );

    JSeparator separator_1 = new JSeparator();
    mnHelp.add( separator_1 );

    JMenuItem mntmAbout = new JMenuItem( "About" );
    mntmAbout.setMnemonic( 'g' );
    mntmAbout.setIcon( new ImageIcon( Main.class
            .getResource( "/org/img/menu-about.png" ) ) );
    mnHelp.add( mntmAbout );


I made some experiments, and it turned out it's not a problem caused by something in my program, but in java or eclipse instead, because even the simplest program like the one whose code I'll paste here has the same problem: `

package testpack;

import java.awt.Dimension;
import javax.swing.*;

public class Main {

    public static void main( String[] args ) {
        JFrame jfr = new JFrame( "" );
        jfr.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        JMenuBar jmb = new JMenuBar();
        JMenu jm = new JMenu( "Hello" );
        JMenuItem jmi = new JMenuItem( "Hi" );
        jm.add( jmi );
        jmb.add( jm );
        jfr.setJMenuBar( jmb );
        jfr.setMinimumSize( new Dimension( 400, 400 ) );
        jfr.setVisible( true );

` ( this is the whole source )

I'm using Mint Cinnamon 13 and Eclipse 4.2. So is there anything I could do to fix the problem?


Unfortunately, it's an java issue with Cinnamon. You can't avoid it unless you

  • switch to SWT (see Eclipse itself, which works fine),
  • switch to another os (they don't run Cinnamon),
  • switch to another window manager.
  • It may be, although not likely, that another JVM doesn't have this issue (f.i. another OpenJDK or even Oracle JVM or alike).

The point is (afaik) that Java is supposed to distinguish the plenty window managers running in linux but recognizes just some of them - not Cinnamon in this particular issue.

Even more sad: the problem seems to occur with Mate as well.

Need Your Help

Skipping and Tearing in Java Animation

java animation tearing

the following code draws a square with two smaller square rotating inside it. whenever you click an arrow on the keyboard, the whole system will move in that direction. however i'm having some prob...

Customized ListView with scolling background


EDIT: Solved this by from Java-code adding headers and footers with transparent background to the ListView.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.