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

3
  • 1
    Don't mix Swing & AWT components without great care and good reason. Use Swing consistently. See Mixing heavy and light components for more details. Commented Aug 29, 2012 at 23:33
  • Can you please post a link to the bug report you filed? Commented Jul 11, 2013 at 16:52
  • @whiskeyspider: 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. Commented Jul 19, 2013 at 9:26

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

5 Comments

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 mail.openjdk.java.net/pipermail/swing-dev/2012-March/… is the default in Java 7.
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
Good. Keep us informed of progress/news.
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 on Windows and on Mac and see the different. In order to solve it, I used code that implement the mouse over events.
Thanks for reporting back. You should turn that comment into an answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.