-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b78
-
generic
-
generic
ADDITIONAL OS VERSION INFORMATION :
Windows XP SP2 32bit
A DESCRIPTION OF THE PROBLEM :
After focus moving into JMenuBar, whose focus traversal key is disabled by default, it never moves to other focusable component.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test case.
sdk/jre/bin/java FocusTraversal
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test finished successfully and silently.
ACTUAL -
Test failed with exception.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.Exception: Problem moving focus from javax.swing.JMenuBar
at FocusTraversal.main(FocusTraversal.java:102)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Portions Copyright (c) 2011 xxxxx Corporation
*/
import java.awt.Component;
import java.awt.ContainerOrderFocusTraversalPolicy;
import java.awt.BorderLayout;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import sun.awt.SunToolkit;
public class FocusTraversal {
static JFrame jf = null;
static Component owner = null;
static final class SetupGui implements Runnable {
public void run() {
jf = new JFrame("Focus traversal test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar mb = new JMenuBar();
mb.add(new JMenu("menu1").add(new JMenuItem("menu_item1")));
JButton jb1 = new JButton("button1");
JButton jb2 = new JButton("button2");
JPanel jp = new JPanel(new BorderLayout());
jp.add(jb1);
jp.add(mb, BorderLayout.NORTH);
jp.add(jb2, BorderLayout.SOUTH);
jf.getContentPane().add(jp);
jf.setFocusTraversalPolicy(
new ContainerOrderFocusTraversalPolicy());
jf.pack();
jb1.requestFocusInWindow();
jf.setVisible(true);
}
}
static final class GetFocusOwner implements Runnable {
public void run() {
owner = jf.getFocusOwner();
}
}
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(50);
SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new SetupGui());
try {
toolkit.realSync();
GetFocusOwner gfo = new GetFocusOwner();
Component last = null;
do {
SwingUtilities.invokeAndWait(gfo);
if (owner == last) {
throw new Exception("Problem moving focus from " +
owner.getClass().getName());
}
last = owner;
// Press the TAB key to move the focus onto the next component
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
toolkit.realSync();
} while (owner != jf);
} finally {
jf.dispose();
}
}
}
---------- END SOURCE ----------
Windows XP SP2 32bit
A DESCRIPTION OF THE PROBLEM :
After focus moving into JMenuBar, whose focus traversal key is disabled by default, it never moves to other focusable component.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test case.
sdk/jre/bin/java FocusTraversal
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test finished successfully and silently.
ACTUAL -
Test failed with exception.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.Exception: Problem moving focus from javax.swing.JMenuBar
at FocusTraversal.main(FocusTraversal.java:102)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Portions Copyright (c) 2011 xxxxx Corporation
*/
import java.awt.Component;
import java.awt.ContainerOrderFocusTraversalPolicy;
import java.awt.BorderLayout;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import sun.awt.SunToolkit;
public class FocusTraversal {
static JFrame jf = null;
static Component owner = null;
static final class SetupGui implements Runnable {
public void run() {
jf = new JFrame("Focus traversal test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar mb = new JMenuBar();
mb.add(new JMenu("menu1").add(new JMenuItem("menu_item1")));
JButton jb1 = new JButton("button1");
JButton jb2 = new JButton("button2");
JPanel jp = new JPanel(new BorderLayout());
jp.add(jb1);
jp.add(mb, BorderLayout.NORTH);
jp.add(jb2, BorderLayout.SOUTH);
jf.getContentPane().add(jp);
jf.setFocusTraversalPolicy(
new ContainerOrderFocusTraversalPolicy());
jf.pack();
jb1.requestFocusInWindow();
jf.setVisible(true);
}
}
static final class GetFocusOwner implements Runnable {
public void run() {
owner = jf.getFocusOwner();
}
}
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(50);
SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new SetupGui());
try {
toolkit.realSync();
GetFocusOwner gfo = new GetFocusOwner();
Component last = null;
do {
SwingUtilities.invokeAndWait(gfo);
if (owner == last) {
throw new Exception("Problem moving focus from " +
owner.getClass().getName());
}
last = owner;
// Press the TAB key to move the focus onto the next component
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
toolkit.realSync();
} while (owner != jf);
} finally {
jf.dispose();
}
}
}
---------- END SOURCE ----------
- relates to
-
JDK-8282046 Create a regression test for JDK-8000326
- Resolved