Skip to main content

swing popup problem on mac osx - java7u6

3 replies [Last post]
darkcrawler
Offline
Joined: 2009-02-05
Points: 0

Hi all,

I've been testing my Swing application on mac os x which runs on an applet. Please note that this applet it always run inside the browser.
A while a ago I noticed that the popups that is shown when you press a JMenu do not receive any mouse over events. So, I did a bit more investigation and I found out that in Java7u6 and when you run an applet in the browser, all the popups are heavyweight by default. In Java6 only if you set the JPopupMenu.setDefaultLightWeightPopupEnabled(false) they become heavyweight;

As you know, when the popups are heavyweight, they have their own window and maybe because of this, the menus inside the popup do not receive mouse over events.

I wrote this little example so you can test:

package com.macos.tests;

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

import javax.swing.*;

public class PopupExample extends JApplet
{
   
    private JPanel topPanel;
    private JMenuBar menuBar;
    private JMenu menuFile;
   
    public static void main(String[] args)
    {
        Frame f = new Frame("DragDropTest");
        f.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent we)
            {
                System.exit(0);
            }
        });
        f.setSize(640, 400);
        Applet a = new PopupExample();
        f.add(a);
        a.init();
        a.start();
        f.setVisible(true);
    }
   
    private void doStart()
    {
       
        topPanel = new JPanel();
        topPanel.setLayout(new BorderLayout());
        getContentPane().add(topPanel);
       
        // Create the menu bar
        menuBar = new JMenuBar();
       
        // Set this instance as the application's menu bar
        setJMenuBar(menuBar);
       
        // Create the file menu
        menuFile = new JMenu("File");
        menuFile.setMnemonic('F');
        menuFile.getPopupMenu().setLightWeightPopupEnabled(true);
        menuBar.add(menuFile);
       
        JMenu menu1 = new JMenu("menu 1");
        JMenu menu2 = new JMenu("menu 2");
        JMenu menu3 = new JMenu("menu 3");
       
        JMenuItem menuItem1 = new JMenuItem("MenuItem 1");
        JMenuItem menuItem2 = new JMenuItem("MenuItem 2");
       
        menu2.add(menu3);
        menu2.add(menuItem1);
        menu2.add(menuItem2);
       
        menuFile.add(menu1);
        menuFile.add(menu2);
       
        setSize(400, 400);
        setBackground(Color.lightGray);
        setVisible(true);
    }
   
    @Override
    public void start()
    {
        try
        {
            SwingUtilities.invokeAndWait(new Runnable()
            {
                public void run()
                {
                    doStart();
                }
            });
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }
}

Just create a new project in eclipse and put that code in a class. Then you must generate a .jar file with that project using the eclipse export functionality - just make sure you choose the above class as Main-Class in the Jar Manifest Specification.

When you have the jar file running, create a html file with the following content:

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

Then run the html file. If you navigate in the menus, you notice that the menus do not receive any mouse-over events.

Can someone - with a mac - test this?
Thanks in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
anthony_p
Offline
Joined: 2006-07-24
Points: 0

Please file a bug at http://bugs.sun.com/

Also, the bug 7171045 seems to be related and is being fixed right now. You may want to try an early access build of 7u8 in a couple of weeks to see if the issue is resolved.

darkcrawler
Offline
Joined: 2009-02-05
Points: 0

Hi Anthony,

I'm in the mailing list so I know they have been taking care of bug 7171045. But that seems different since is for enter / exist events during drag...

So, I'll submit a bug for this.
Is 'Java Plug-in' the Product/Category? And what should be the Subcategory?

Thanks

anthony_p
Offline
Joined: 2006-07-24
Points: 0

This must be an AWT bug, so I suggest to use java/java/classes_awt for Product/Category/Subcategory.