-
Bug
-
Resolution: Fixed
-
P4
-
1.2.1
-
beta2
-
generic
-
generic
Name: skT88420 Date: 04/27/99
/*
Dismissing an internal JOptionPane doesn't restore the focus.
I consider this a bug, since a JOptionPane shouldn't affect anything
in the parent component.
Run this application. start typing into the field. When you exceed
4 characters, an internal JOptionPane will appear. When you dismiss
the message, the text field should still have the focus, but it doesn't.
I tested this on Windows 98, but I'm assuming it's platform independent
*/
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.awt.event.*;
import java.awt.*;
public class OptionPaneFocusBug
implements DocumentListener
{
public static void main(String[] args)
{
JFrame mf = new JFrame("Option Pane Bug");
mf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
mf.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
Container cp = mf.getContentPane();
cp.setLayout(new FlowLayout());
JTextField fld = new JTextField(40);
Document doc = fld.getDocument();
doc.addDocumentListener(new OptionPaneFocusBug(mf));
cp.add(fld);
mf.setBounds(10, 10, 400, 300);
mf.show();
fld.requestFocus();
}
JFrame myFrame;
OptionPaneFocusBug(JFrame ff)
{
myFrame = ff;
}
public void insertUpdate(DocumentEvent evt)
{
Document doc = evt.getDocument();
if (doc.getLength() > 4)
JOptionPane.showInternalMessageDialog
(myFrame.getContentPane(), "No more than 4 chars allowed");
}
public void removeUpdate(DocumentEvent e) {}
public void changedUpdate(DocumentEvent e) {}
}
(Review ID: 57560)
======================================================================
- relates to
-
JDK-4333326 Multiple active carets - ambiguous focus
- Closed