4

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

Luis Gonçalves
  • 249
  • 2
  • 10
  • 1
    Don't mix Swing & AWT components without great care and good reason. Use Swing consistently. See [Mixing heavy and light components](http://java.sun.com/products/jfc/tsc/articles/mixing/) for more details. – Andrew Thompson Aug 29 '12 at 23:33
  • Can you please post a link to the bug report you filed? – martinez314 Jul 11 '13 at 16:52
  • @whiskeyspider: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7194878 Honestly I dont think they will ever solve this problem. Apple is also trying to remove java from their systems, so you will have many other problems if you want to run an application within an applet. – Luis Gonçalves Jul 19 '13 at 09:26

1 Answers1

4

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

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Out of curiosity, which JRE did you use? Did you run the applet in the browser? If I run the program as an application, this works fine. The problem only comes up when you run the applet in the browser. And by the way, this was happening also using jre6u33 if you use heavyweight popups, which according to http://mail.openjdk.java.net/pipermail/swing-dev/2012-March/001963.html is the default in Java 7. – Luis Gonçalves Aug 30 '12 at 08:03
  • 1
    This problem does not happen in Windows or Linux with any JRE version I tested. This only happens on mac OS X. I raised a bug fir this issue. Thanks – Luis Gonçalves Aug 30 '12 at 09:06
  • Good. Keep us informed of progress/news. – Andrew Thompson Aug 30 '12 at 10:10
  • 1
    I encounter the same issue with JComboBox. When mouse is over the items on Mac applet the item is not highlight. On windows it work perfect. You can run this online swing applet demo [linkk](http://securetechnologies.com/CCAT/SwingDemoApplet.html) on Windows and on Mac and see the different. In order to solve it, I used code that implement the mouse over events. – Amos N. Feb 13 '13 at 13:52
  • Thanks for reporting back. You should turn that comment into an answer. – Andrew Thompson Feb 13 '13 at 13:55