Mailing Lists: Apple Mailing Lists

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

Re: Window focus lost when help menu selected



On Sep 5, 2008, at 11:03 AM, Rob Juurlink wrote:

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.

This is because Java applications lose their focus when the app window loses "key" focus, and not when the window loses "main". The difference between key and main are distinctions made inside AppKit (document windows can stay "main" while a palette gains "key" focus, because you need to type in say, a font size). In Java we should be triggering off of the windowDidResignMain, and not the windowDidResignKey notification.


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.

It doesn't work in 64-bit apps in Leopard.

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);
	}
}

Great test case. I'd say "file a bug", but we've got this one, and we'd only return your dupe. I've added this to our existing bug on this issue.


Thanks much,
Mike Swingler
Java Runtime Engineer
Apple Inc.
_______________________________________________
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
References: 
 >Window focus lost when help menu selected (From: Rob Juurlink <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.