-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
sparc
-
solaris_2.6
Name: dbT83986 Date: 03/30/99
Below is the demo program. See the comment at the top for
everything you need to reproduce this one.
/*
This bug only happens on Solaris. It happens in both
JDK 1.2 and Swing 1.0.2.
With useJSplitPane set to true, see the bug as follows:
1. click in textfield and type
2. change X focus to another window (note focusLost)
3. click in textfield and type again
4. resize the window
5. click in textfield and type again
6. change X focus to another window (bug is no focusLost
and you never can get focusLost on the textfield again)
Set useJSplitPane to false and repeat the steps. This uses a Jpanel
instead of a JSplitPane. This has no problem. It gives focusLost
forever as it should.
To compile and run:
> javac JSplitPaneFocusBug.java
> java JSplitPaneFocusBug
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JSplitPaneFocusBug extends JFrame {
public JSplitPaneFocusBug() {
boolean useJSplitPane = true; // cut and paste these: true or false
JTextField tf = new JTextField();
tf.setEditable(true);
tf.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) { System.out.println("JTextField focusGained"); }
public void focusLost(FocusEvent e) { System.out.println("JTextField focusLost"); }
});
if (useJSplitPane) {
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true);
splitPane.setTopComponent(tf);
splitPane.setBottomComponent(new JLabel("foo"));
getContentPane().add(splitPane, BorderLayout.CENTER);
} else { // use a JPanel
JPanel panel = new JPanel(new BorderLayout());
panel.add(tf, "North");
panel.add(new JLabel("foo"), "South");
getContentPane().add(panel, BorderLayout.CENTER);
}
}
public static void main(String args[]) {
JSplitPaneFocusBug m = new JSplitPaneFocusBug();
m.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { System.exit(0); } });
m.setSize(300, 250); m.setLocation(20, 20); m.show();
}
}
(Review ID: 56311)
======================================================================
- duplicates
-
JDK-4290675 Focus Management Enhancements
- Closed