简体   繁体   English

Swing菜单Java 7 mac osx

[英]Swing menus Java 7 mac osx

I've been testing my Swing application on mac os x which runs on an applet. 我一直在mac os x上测试我的Swing应用程序,它运行在applet上。

When I run this applet in the browser, I noticed that the mouse-over on the JMenus/JMenuItems do not work correctly. 当我在浏览器中运行此applet时,我注意到JMenus / JMenuItems上的鼠标悬停无法正常工作。

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. 使用此代码,生成.jar文件。 In Eclipse you can use the Export functionality and only make sure you define the Main-Class as the class above. 在Eclipse中,您可以使用导出功能,并且只确保将Main-Class定义为上面的类。

Once you have the jar up an running, create an html file with the content: 让jar运行后,创建一个包含内容的html文件:

<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. 在此之后,运行html文件并检查菜单:它们不应该接收鼠标悬停事件。 Am I doing something wrong? 难道我做错了什么? Is this a Java bug? 这是一个Java错误吗? Any mac user out there to test this problem? 有没有mac用户来测试这个问题?

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). 我正在使用Mac的最新Oracle JRE运行Mac OSX 10.7.4(http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1637588.html)。 Used Firefox to test this. 用Firefox测试这个。

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. 我怀疑这是JRE中的一个错误。

Change the code to: 将代码更改为:

  1. Dump java.version & java.vendor 转储java.versionjava.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 : 从此属性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 浏览器: FireFox 15.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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