简体   繁体   中英

Swing menus Java 7 mac osx

I've been testing my Swing application on mac os x which runs on an applet.

When I run this applet in the browser, I noticed that the mouse-over on the JMenus/JMenuItems do not work correctly.

Here is a small program to reproduce the problem:

package com.macosx.tests;

import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;

import javax.swing.*;

public class Example extends JApplet {

    JMenuBar bar;
    JMenu file, edit;
    JMenuItem new1, save, close;

    private void doStart() {
        bar = new JMenuBar();

        file = new JMenu("File");
        edit = new JMenu("Edit");

        new1 = new JMenuItem("New");
        save = new JMenuItem("Save");
        close = new JMenuItem("Close");

        setJMenuBar(bar);
        bar.add(file);
        bar.add(edit);
        file.add(new1);
        file.add(save);
        file.add(close);
    }

    @Override
    public void start() {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    doStart();
                }
            });
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

With this code, generate a .jar file. In Eclipse you can use the Export functionality and only make sure you define the Main-Class as the class above.

Once you have the jar up an running, create an html file with the content:

<html>
<head>
<title>Menu test Applet</title>
</head>
<body>
<applet id="appletID" height="800" width="600" 
  code="com.macosx.tests.Example" 
  archive="tests.jar">
</applet>
</div>
</body>
</html>  

After this, run the html file and check the menus: they should not receive mouse-over events. Am I doing something wrong? Is this a Java bug? Any mac user out there to test this problem?

I'm running Mac OSX 10.7.4 with latest Oracle JRE for mac (http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1637588.html). Used Firefox to test this.

java.vendor     Oracle Corporation
java.version    1.7.0_06
os.name         Mac OS X
os.version      10.7.4

Thanks

The code works fine here. I suspect it is a bug in that JRE.

Change the code to:

  1. Dump java.version & java.vendor
  2. Remove the main (which just confuses things) - then..
  3. Raise a bug report.

Details of test machine

Details obtained from this properties applet :

Name            Value
java.vendor     Oracle Corporation
java.version    1.7.0_05
os.name         Windows 7
os.version      6.1

Browser: FireFox 15.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM