-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.4.2
-
x86
-
windows_2000
Name: jk109818 Date: 08/19/2003
FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
When a popup that contains a JTextField is placed partially or totally outside a JFrame window bounds, the JTextField does not react to either mouse or keyboard input. Components such as JCheckBox or JComboBox work correctly under the same circumstances.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a JFrame that creates a Popup containing a JTextField with text, and locate the popup in such a way that the popup is partially or totally outside the JFrame window boundries. Attempt to edit the text with the keyboard, or select or set the text cursor with either the keyboard or the mouse.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The user should be able to edit the text in the popup's JTextField using either the keyboard or the mouse.
ACTUAL -
The text in the popup's JTextField cannot be edited with either the keyboard or the mouse.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package popupbug;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
* This program demostrates a bug with JTextField popups in Java 1.4.x.
* When the popup is placed partially or totally outside the JFrame bounds,
* the JTextField does not react to either mouse or keyboard input.
* <p>
* Run the program, and click on the label where indicated to bring up a
* JTextField popup. Click and edit the JTextField and press ENTER. The
* label will change indicating a new location to click. Click where
* indicated to bring up a JTextField popup that is partially outside the
* JTextField bounds. Clicking or typing in the JTextField has no effect.
*/
public class PopupBug extends JFrame {
JLabel jLabel1 = new JLabel();
public PopupBug() {
final JLabel jLabel1 = new JLabel("Click here [x]");
jLabel1.setSize(jLabel1.getPreferredSize());
jLabel1.setLocation(0,30);
// show popup with mouse click on label
jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// create text field to popup
String editText = "Edit me";
JTextField jTextField1 = new JTextField(editText);
// create popup for text field centered at the mouse location
Point p = new Point(e.getX()-jLabel1.getWidth()/2, e.getY()-jLabel1.getHeight()/2);
SwingUtilities.convertPointToScreen(p, jLabel1);
PopupFactory popupFactory = PopupFactory.getSharedInstance();
final Popup popup = popupFactory.getPopup(jLabel1, jTextField1, p.x, p.y);
// hide popup and change label text when editing completed
jTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jLabel1.setText("[x] Click here");
popup.hide();
}
});
// shop popup
popup.show();
}
});
// place label in JFrame content pane
this.getContentPane().setLayout(null);
this.getContentPane().add(jLabel1);
this.setBounds(100, 100, 100,100);
}
public static void main(String[] args) {
PopupBug PopupBug = new PopupBug();
PopupBug.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
PopupBug.show();
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Replace the use of Popup with an undecorated frame. Rather than calling:
PopupFactory factory = PopupFactory.getSharedInstance();
Popup popup = popupFactory.getPopup(popupParent,textField,popupX,popupY);
popup.show();
...
popup.hide();
use the following code instead:
Frame frame = (Frame)SwingUtilities.getAncestorOfClass(Frame.class,popupParent);
Dialog popup = null;
if (frame != null) {
popup = new Dialog(frame);
popup.setUndecorated(true);
popup.setModal(false);
popup.setLayout(BorderLayout());
popup.add(popupTextField, BorderLayout.CENTER);
popup.setBounds(popupX, popupY, textField.width, textField.height);
popup.show();
}
...
if (popup != null) {
popup.hide();
popup.dispose();
popup = null;
}
(Incident Review ID: 191326)
======================================================================