-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.0.2
-
x86
-
windows_nt
In the test case below, give focus to the second JTextfield and press
enter. Dismiss dialog 1.
On win32, when the second dialog comes up, both the dialog's ok button and textfield 2 have focus (or at least the caret is active). When dialog 2 is
dismissed, both textfield 1 and textfield 2 appear to have the focus -- the
caret is active in both textfields.
This has been tested with 1.1.7L and Swing 1.0.2, 1.0.3, and 1.1beta3 with identical results.
_______________________________ DoubleFocus.java -------------------------------
import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DoubleFocus extends JInternalFrame {
public DoubleFocus() {
setSize(400, 300);
getContentPane().setLayout(new FlowLayout());
tf1.setColumns(10);
tf2.setColumns(16);
getContentPane().add(tf1);
getContentPane().add(tf2);
getContentPane().add(targetButton);
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
tf2.getKeymap().removeKeyStrokeBinding(enter);
getRootPane().setDefaultButton(targetButton);
targetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
tf1.setText("");
tf2.setText("");
doDlgSequence();
}
});
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println("Could not set L&F: " + e);
e.printStackTrace();
}
frame = new JFrame();
frame.setSize(800, 600);
JDesktopPane dt = new JDesktopPane();
frame.getContentPane().add(dt);
frame.setVisible(true);
DoubleFocus bt = new DoubleFocus();
dt.add(bt);
dlg = new Dlg1(frame);
}
public void doDlgSequence() {
showDlg1();
showDlg2();
}
public void showDlg1() {
dlg.setVisible(true);
}
public void showDlg2() {
JOptionPane.showMessageDialog(frame, "This is dlg 2", "2",
JOptionPane.ERROR_MESSAGE);
tf1.requestFocus();
}
JButton targetButton = new JButton("Don't Press");
static Dlg1 dlg ;
static JFrame frame;
JTextField tf1 = new JTextField("Tab to next");
JTextField tf2 = new JTextField("Press enter here");
}
class Dlg1 extends JDialog {
public Dlg1(Frame frame) {
super(frame);
setSize(200, 200);
getContentPane().setLayout(new FlowLayout());
getContentPane().add(label);
getContentPane().add(button);
setModal(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
setVisible(false);
}
});
}
JButton button = new JButton("OK");
JLabel label = new JLabel("This is dialog 1");
}
--------------------------------------------------------------------------------
Added by Nick Rodin 1998-09-28:
This bug report has been updated to reflect only the problem occurring with win32. Bug #4176949 has been filed to report a separate Solaris issue.
This bug is a regression from the 1.1.6 functionality.
This bug may be caused by a similar AWT problem. See bug #4176602.
enter. Dismiss dialog 1.
On win32, when the second dialog comes up, both the dialog's ok button and textfield 2 have focus (or at least the caret is active). When dialog 2 is
dismissed, both textfield 1 and textfield 2 appear to have the focus -- the
caret is active in both textfields.
This has been tested with 1.1.7L and Swing 1.0.2, 1.0.3, and 1.1beta3 with identical results.
_______________________________ DoubleFocus.java -------------------------------
import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DoubleFocus extends JInternalFrame {
public DoubleFocus() {
setSize(400, 300);
getContentPane().setLayout(new FlowLayout());
tf1.setColumns(10);
tf2.setColumns(16);
getContentPane().add(tf1);
getContentPane().add(tf2);
getContentPane().add(targetButton);
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
tf2.getKeymap().removeKeyStrokeBinding(enter);
getRootPane().setDefaultButton(targetButton);
targetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
tf1.setText("");
tf2.setText("");
doDlgSequence();
}
});
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println("Could not set L&F: " + e);
e.printStackTrace();
}
frame = new JFrame();
frame.setSize(800, 600);
JDesktopPane dt = new JDesktopPane();
frame.getContentPane().add(dt);
frame.setVisible(true);
DoubleFocus bt = new DoubleFocus();
dt.add(bt);
dlg = new Dlg1(frame);
}
public void doDlgSequence() {
showDlg1();
showDlg2();
}
public void showDlg1() {
dlg.setVisible(true);
}
public void showDlg2() {
JOptionPane.showMessageDialog(frame, "This is dlg 2", "2",
JOptionPane.ERROR_MESSAGE);
tf1.requestFocus();
}
JButton targetButton = new JButton("Don't Press");
static Dlg1 dlg ;
static JFrame frame;
JTextField tf1 = new JTextField("Tab to next");
JTextField tf2 = new JTextField("Press enter here");
}
class Dlg1 extends JDialog {
public Dlg1(Frame frame) {
super(frame);
setSize(200, 200);
getContentPane().setLayout(new FlowLayout());
getContentPane().add(label);
getContentPane().add(button);
setModal(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
setVisible(false);
}
});
}
JButton button = new JButton("OK");
JLabel label = new JLabel("This is dialog 1");
}
--------------------------------------------------------------------------------
Added by Nick Rodin 1998-09-28:
This bug report has been updated to reflect only the problem occurring with win32. Bug #4176949 has been filed to report a separate Solaris issue.
This bug is a regression from the 1.1.6 functionality.
This bug may be caused by a similar AWT problem. See bug #4176602.
- duplicates
-
JDK-4176602 Request Focus Fails with Consecutive Dialogs
- Closed
- relates to
-
JDK-4176949 Highlighting Problem with Consecutive Modal JDialogs on Solaris
- Closed
-
JDK-4178187 requestFocus not working in 1.1.7
- Closed