Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Window focus lost when help menu selected



In OS X 10.5 Leopard, when I select the help menu of a Java application,
the application frame loses its focus,  a focus lost event is fired.

However, native application like e.g. ITunes, keep the window focus.


Tested in both Java 6 and Java 5. I think this is not the right
behavior. Can anyone confirm this?

btw, the brushMetalLook gradual gray gradient is not working in Java 6.



Sample code to reproduce the problem:



import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;

/**
 * Test frame focus
 */
public class FrameFocusTest extends JFrame {

	public static void main(String[] args) {

		System.setProperty("apple.laf.useScreenMenuBar", "true");
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame lFrame = new FrameFocusTest();
				lFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				lFrame.setSize(300, 200);

				// Center frame
				lFrame.setLocationRelativeTo(null);
				lFrame.setVisible(true);
			}
		});
	}


	/**
	 * Default constructor
	 */
	public FrameFocusTest() {

		setTitle("Testing Frame Focus");
		addMenus();

		final JLabel lLblFocus = new JLabel("Focussed");
		lLblFocus.setHorizontalAlignment(SwingConstants.CENTER);
		lLblFocus.setOpaque(false);

		JPanel lContentPane = new JPanel(new BorderLayout()) {
			@Override
			protected void paintComponent(Graphics g) {
				if (isOpaque()) {
					g.setColor(isFocused() ? Color.RED : Color.WHITE);
					g.fillRect(0, 0, getWidth(), getHeight());
				}
				super.paintComponents(g);

			}
		};
		lContentPane.setOpaque(true);
		lContentPane.add(lLblFocus);
		setContentPane(lContentPane);

		/**
		 * Draw focus change
		 */
		addWindowFocusListener(new WindowFocusListener() {
			public void windowGainedFocus(WindowEvent e) {
				lLblFocus.setText("Focussed");
				// Repaint background
				repaint();
			}

			public void windowLostFocus(WindowEvent e) {
				lLblFocus.setText("Not Focussed");
				// Repaint background
				repaint();
			}
		});
	}

	/**
	 * Dummy menu
	 */
	public void addMenus() {
		JMenuBar lMainMenuBar = new JMenuBar();
		JMenu lHelpMenu = new JMenu("Help");
		lMainMenuBar.add(lHelpMenu);
		lHelpMenu.add(new JMenuItem("Online Documentation"));
		lHelpMenu.add(new JMenuItem("Technical Support"));
		setJMenuBar(lMainMenuBar);
	}
}

Attachment: Picture 21.png
Description: PNG image

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.