-
Bug
-
Resolution: Fixed
-
P2
-
1.2.0
-
1.2fcs
-
sparc
-
solaris_2.5.1
-
Not verified
This may be related to bug 4147446, however the symptoms here are more severe. I'm using jdk 1.1.6 and swing 1.0.2. I've provided a simple test case below. When the window comes up, click on the Hello button in the first tab. Then move to the second tab and click in the JTextField. It will accept input without a cursor yet when the Enter key is pressed, the listener is not called. Click back on the first tab and then go back to the second. Now the cursor is displayed and the listener is called. A more severe variation is to uncomment the line which adds the JButton directly to the JTabbedPane (then comment out the line which adds TestPanel1). In this case, the listener is never called no matter what actions are taken. import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class Test {
public static void main(String args[]) {
JTabbedPane tp = new JTabbedPane();
//tp.addTab("Test1", new JButton("Hello"));
tp.addTab("Test1", new TestPanel1());
tp.addTab("Test2", new TestPanel2());
JFrame jf = new JFrame();
jf.getContentPane().add(tp);
jf.pack();
jf.show();
}
}
class TestPanel1 extends JPanel {
public TestPanel1() {
add(new JButton("Hello"));
}
}
class TestPanel2 extends JPanel {
public TestPanel2() {
setLayout(new GridLayout(2,1));
JTextField tf = new JTextField();
tf.addActionListener(new TfListener());
add(tf);
JSplitPane sp = new JSplitPane();
add(sp);
}
}
class TfListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("actionListener");
}
}
import java.awt.event.*;
import com.sun.java.swing.*;
public class Test {
public static void main(String args[]) {
JTabbedPane tp = new JTabbedPane();
//tp.addTab("Test1", new JButton("Hello"));
tp.addTab("Test1", new TestPanel1());
tp.addTab("Test2", new TestPanel2());
JFrame jf = new JFrame();
jf.getContentPane().add(tp);
jf.pack();
jf.show();
}
}
class TestPanel1 extends JPanel {
public TestPanel1() {
add(new JButton("Hello"));
}
}
class TestPanel2 extends JPanel {
public TestPanel2() {
setLayout(new GridLayout(2,1));
JTextField tf = new JTextField();
tf.addActionListener(new TfListener());
add(tf);
JSplitPane sp = new JSplitPane();
add(sp);
}
}
class TfListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("actionListener");
}
}