JDK-4381458 : Apparent infinite loop when tabbing on Canvas in JFrame (focus traversal)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2000-10-20
  • Updated: 2000-12-05
  • Resolved: 2000-12-05
Related Reports
Duplicate :  
Description

Name: yyT116575			Date: 10/20/2000


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Here's a test case. Click on the canvas, then press TAB a bunch of times. The
CPU usage goes to 100% and you can no longer select the pulldown menu. I think
the problem is focus traversal when you have a heavyweight Canvas in a JFrame
with a JMenuBar. (I need to do this, since I use a heavyweight Canvas3D with
Java3D, and have the same problem.)

import java.awt.*;
import javax.swing.*;

public class Class1 {
	public static void main(String[] args) {

		JPanel panel = new JPanel(new BorderLayout());
		Canvas canvas = new Canvas();
		canvas.setSize(300, 300);
		JMenuBar mb = new JMenuBar();
		JMenu menu = new JMenu("Howdy");
		menu.getPopupMenu().setLightWeightPopupEnabled(false);
		menu.add(new JMenuItem("You there!"));
		mb.add(menu);
		panel.add(mb, BorderLayout.NORTH);
		panel.add(canvas, BorderLayout.CENTER);

		// Including these three lines prevents a lockup that can occur
		// when hitting TAB repeatedly after
		// clicking in the image. Appears to be a Swing bug.
//		JButton b = new JButton();
//		b.setBorder(BorderFactory.createEmptyBorder());
//		panel.add(b, BorderLayout.SOUTH);

		JFrame frame = new JFrame("Hey");
		frame.getContentPane().add(panel, BorderLayout.CENTER);
		frame.pack();
		frame.setVisible(true);
	}
}

A thread dump reveals the culprit, I think. It is probably in an infinite
loop on getNextComponent() or something like that:

"AWT-EventQueue-0" prio=7 tid=0x804b40 nid=0x460 waiting on monitor
[0x8e6f000..
0x8e6fdc4]
        at java.awt.Component.bounds(Unknown Source)
        at java.awt.Component.getBounds(Unknown Source)
        at javax.swing.DefaultFocusManager.compareTabOrder(Unknown Source)
        at javax.swing.DefaultFocusManager.childrenTabOrder(Unknown Source)
        at javax.swing.DefaultFocusManager.getFirstComponent(Unknown Source)
        at javax.swing.DefaultFocusManager.getNextComponent(Unknown Source)
        at
javax.swing.DefaultFocusManager.getFocusableComponentAfter(Unknown So
urce)
        at javax.swing.DefaultFocusManager.focusNextComponent(Unknown
Source)
        at javax.swing.DefaultFocusManager.processKeyEvent(Unknown Source)
        at javax.swing.JComponent.processKeyEvent(Unknown Source)
        at javax.swing.JMenu.processKeyEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processKeyEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
(Review ID: 110045) 
======================================================================

Comments
WORK AROUND Name: yyT116575 Date: 10/20/2000 Add a tiny (almost invisible) JButton to the panel, which seems to fix the focus traversal problems. ======================================================================
2004-06-11

EVALUATION This was fixed as part of 4290675. scott.violet@eng 2000-12-05
2000-12-05