-
Bug
-
Resolution: Fixed
-
P3
-
7, 8, 9
-
b114
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
From an applet environment viewed through a browser, the following structure creates "unreachable" text fields.
JApplet -> JButton => (spawns JPopupMenu)
JPopupMenu -> JMenu -> JTextField
Other controls that contain a text filed such as JSpinner also exhibit this behavior. While the buttons of the spinner can be pressed, the text filed does not receive focus and thus cannot be interacted with.
Observations:
- This behavior occurs beginning with Java 7 (1.7.0) and appears to be present through all versions up to and including Java 8 update 45.
- This behavior is not present in Java 6.
- This behavior occurs from Windows XP, Windows 7, Windows 8 (8.1)
- The behavior does not occur with Linux.
- This behavior does not occur when run as an application, nor does it occur from within an applet viewer.
- The behavior seems to occur regardless of browser (Chrome, IE, Firefox).
- The behavior only occurs if the menu is spawned from a control rooted on the applet itself; a JPopupMenu spawned from within a JDialog (or any window type) works as expected.
- Replacing the content pane does not affect the behavior. Attempts to request or grab focus via an ActionListener make no difference (they fail).
- The behavior remains the same regardless of whether or not the menu area is within the bounds of the applet area or exceeds those bounds.
- The behavior remains regardless of the order that I build (add) the menu components.
- Targeting specific JDK or source level makes no difference.
- Nesting the text field directly in the JPopupMenu (instead of a JMenu within the JPopupMenu) results in correct behavior (focus enters the text field).
It seems there is a disconnect between the popup menu that a JMenu uses internally and the focus manager, or something similar. Since fields added directly to a popup can get focus, but those added to a JMenu (then the JMenu added to the JPopupMenu) cannot, somehow the popup within the JMenu must not be properly registered somewhere or does not add appropriate listeners somehow.
I recognize that the above is an unusual use of a menu, but we have created a menu to select certain items while allow others to offer fields that can be filled in where a dialog is simply too heavy-handed.
REGRESSION. Last worked in version 6u45
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a JApplet with a button that will show a JPopupMenu (with button as invoker) via ActionListener. Create the JPopupMenu and add a JMenu within the popup. Add a JTextField to the JMenu. View the applet using browser via normal applet hosting, not an appletviewer.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JTextField receives focus and user can type in field.
ACTUAL -
JTextField never receives focus; user cannot interact with field.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
public class FailingExample extends JApplet
{
public void init() {
super.init();
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
final JButton button = new JButton("Press Me");
final JPopupMenu popup = new JPopupMenu();
JTextField field = new JTextField("JTextField");
JMenu menu = new JMenu("Menu");
cp.add(button);
popup.add(menu);
menu.add(field);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
popup.show(button, 0, button.getHeight());
}
});
field.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e) {
System.out.println("focus lost");
}
public void focusGained(FocusEvent e) {
System.out.println("focus gained");
}
});
}
}
// -------------------------------------- Test HTML
<html>
<head>
<title>Testing Menus</title>
</head>
<body>
<applet
id="MenuTester"
name="Testing Menus"
style="width: 250px; height: 150px;"
archive="jars/Testing.jar"
code="test.FailingExample.class">
</applet>
</body>
</html>
---------- END SOURCE ----------
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
From an applet environment viewed through a browser, the following structure creates "unreachable" text fields.
JApplet -> JButton => (spawns JPopupMenu)
JPopupMenu -> JMenu -> JTextField
Other controls that contain a text filed such as JSpinner also exhibit this behavior. While the buttons of the spinner can be pressed, the text filed does not receive focus and thus cannot be interacted with.
Observations:
- This behavior occurs beginning with Java 7 (1.7.0) and appears to be present through all versions up to and including Java 8 update 45.
- This behavior is not present in Java 6.
- This behavior occurs from Windows XP, Windows 7, Windows 8 (8.1)
- The behavior does not occur with Linux.
- This behavior does not occur when run as an application, nor does it occur from within an applet viewer.
- The behavior seems to occur regardless of browser (Chrome, IE, Firefox).
- The behavior only occurs if the menu is spawned from a control rooted on the applet itself; a JPopupMenu spawned from within a JDialog (or any window type) works as expected.
- Replacing the content pane does not affect the behavior. Attempts to request or grab focus via an ActionListener make no difference (they fail).
- The behavior remains the same regardless of whether or not the menu area is within the bounds of the applet area or exceeds those bounds.
- The behavior remains regardless of the order that I build (add) the menu components.
- Targeting specific JDK or source level makes no difference.
- Nesting the text field directly in the JPopupMenu (instead of a JMenu within the JPopupMenu) results in correct behavior (focus enters the text field).
It seems there is a disconnect between the popup menu that a JMenu uses internally and the focus manager, or something similar. Since fields added directly to a popup can get focus, but those added to a JMenu (then the JMenu added to the JPopupMenu) cannot, somehow the popup within the JMenu must not be properly registered somewhere or does not add appropriate listeners somehow.
I recognize that the above is an unusual use of a menu, but we have created a menu to select certain items while allow others to offer fields that can be filled in where a dialog is simply too heavy-handed.
REGRESSION. Last worked in version 6u45
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a JApplet with a button that will show a JPopupMenu (with button as invoker) via ActionListener. Create the JPopupMenu and add a JMenu within the popup. Add a JTextField to the JMenu. View the applet using browser via normal applet hosting, not an appletviewer.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JTextField receives focus and user can type in field.
ACTUAL -
JTextField never receives focus; user cannot interact with field.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
public class FailingExample extends JApplet
{
public void init() {
super.init();
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
final JButton button = new JButton("Press Me");
final JPopupMenu popup = new JPopupMenu();
JTextField field = new JTextField("JTextField");
JMenu menu = new JMenu("Menu");
cp.add(button);
popup.add(menu);
menu.add(field);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
popup.show(button, 0, button.getHeight());
}
});
field.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e) {
System.out.println("focus lost");
}
public void focusGained(FocusEvent e) {
System.out.println("focus gained");
}
});
}
}
// -------------------------------------- Test HTML
<html>
<head>
<title>Testing Menus</title>
</head>
<body>
<applet
id="MenuTester"
name="Testing Menus"
style="width: 250px; height: 150px;"
archive="jars/Testing.jar"
code="test.FailingExample.class">
</applet>
</body>
</html>
---------- END SOURCE ----------