JDK-4259274 : Focus problem with two JFrames
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-08-03
  • Updated: 2000-10-24
  • Resolved: 2000-10-24
Related Reports
Duplicate :  

Name: skT88420			Date: 08/03/99

The problem is that if you programatically setVisible(false) on a JFrame on Win32, the focus is lost, ie. nothing has focus.  Perhaps this is the desired behavior but I doubt it since this isn't what happens on Solaris.  Moreover, once the focus is lost in this manner, if you press TAB without clicking on the visible frame, you get a NullPointerException.

Steps to reproduce the problem:
1. Run the code below.
2. Notice that the visible frame does not have focus.
3. Press TAB and get the following exception:

	at javax.swing.DefaultFocusManager.childrenTabOrder(DefaultFocusManager.java:347)
	at javax.swing.DefaultFocusManager.tabOrderNextComponent(DefaultFocusManager.java:296)
	at javax.swing.DefaultFocusManager.getComponentAfter(DefaultFocusManager.java:253)
	at javax.swing.DefaultFocusManager.getNextComponent(DefaultFocusManager.java:184)
	at javax.swing.DefaultFocusManager.getFocusableComponentAfter(DefaultFocusManager.java:158)
	at javax.swing.DefaultFocusManager.focusNextComponent(DefaultFocusManager.java:90)
	at javax.swing.DefaultFocusManager.processKeyEvent(DefaultFocusManager.java:75)
	at javax.swing.JComponent.processKeyEvent(JComponent.java:1527)
	at java.awt.Component.processEvent(Component.java:3008)
	at java.awt.Container.processEvent(Container.java:990)
	at java.awt.Component.dispatchEventImpl(Component.java:2394)
	at java.awt.Container.dispatchEventImpl(Container.java:1035)
	at java.awt.Component.dispatchEvent(Component.java:2307)
	at java.awt.LightweightDispatcher.processKeyEvent(Container.java:1766)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1740)
	at java.awt.Container.dispatchEventImpl(Container.java:1022)
	at java.awt.Window.dispatchEventImpl(Window.java:749)
	at java.awt.Component.dispatchEvent(Component.java:2307)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:287)
	at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:92)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:83)

-------------------- CODE BELOW -----------------------

import javax.swing.*;

public class FocusTest {

    public static void main(String[] args) {
	final JFrame frame1 = new JFrame("Test 1");
	final JFrame frame2 = new JFrame("Test 2");

	SwingUtilities.invokeLater(new Runnable() {
	    public void run() {


This is exhibited on WinNT 4.0 Service Pack 5 and on Win98.

The java version is JDK 1.2.2-W
(Review ID: 93404) 

WORK AROUND Name: skT88420 Date: 08/03/99 You can do a requestFocus (a couple of times probabaly necessary) - IF you have a reference to the component that should get focus. ======================================================================

EVALUATION I can't reproduce the crash mentioned in the Comments section, but the NPE does occur on Windows. We need to 1. get rid of the NPE, and 2. try to get the focus to the remaining frame, I suppose... hania.gajewska@Eng 1999-09-16