-
Bug
-
Resolution: Won't Fix
-
P3
-
1.4.2
-
sparc
-
solaris_8
FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
SunOS grovss37 5.8 Generic_108528-29 sun4u sparc SUNW,Ultra-5_10
A DESCRIPTION OF THE PROBLEM :
If a JFormattedTextField is constructed with a javax.swing.text.MaskFormatter
and a 'PERSIST' or 'COMMIT' focus lost behavior is used, the currently edited value is
always considered as valid when it's incomplete.
This problem does not exist when the MaskFormatter 'commitOnEdit' property is true.
This is due to the 'run()' method in JFormattedTextField.FocusLostHandler class.
In the case of 'PERSIST' or 'COMMIT' focus lost behavior, it does not update 'editValid'.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Launch the test case and type only one valid character (digit) then click the 'Verify' button
to see the value of 'editValid'.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.BorderFactory;
import javax.swing.WindowConstants;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.Box;
import javax.swing.text.MaskFormatter;
import java.text.ParseException;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;
public class FormattedTextTest extends JFrame
{
public FormattedTextTest() {
super("FormattedTextTest");
// Create a mask.
MaskFormatter formatter = null;
try {
formatter = new MaskFormatter("##$##");
}
catch (ParseException e) {
e.printStackTrace();
System.exit(-1);
}
formatter.setPlaceholderCharacter('_');
//formatter.setCommitsOnValidEdit(true);
// Create a formatted text field.
final JFormattedTextField ftf = new JFormattedTextField(formatter);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
//ftf.setFocusLostBehavior(JFormattedTextField.COMMIT);
ftf.setMaximumSize(ftf.getPreferredSize());
ftf.setMinimumSize(ftf.getPreferredSize());
// Create a label.
JLabel label = new JLabel("Price : ");
label.setLabelFor(ftf);
// Create a panel.
Box pan = Box.createHorizontalBox();
pan.add(label);
pan.add(ftf);
// Create a button.
JButton button = new JButton("Verify");
//button.setMargin(new Insets(0,0,0,0));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Edit valid : " + ftf.isEditValid());
Toolkit.getDefaultToolkit().beep();
}
});
JPanel contentPane = new JPanel();
BoxLayout box = new BoxLayout(contentPane, BoxLayout.Y_AXIS);
contentPane.setLayout(box);
contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
contentPane.add(pan);
contentPane.add(Box.createVerticalStrut(10));
contentPane.add(button);
setContentPane(contentPane);
}
public static void main(String[] args) {
try {
JFrame frame = new FormattedTextTest();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
catch (Exception e) {
e.printStackTrace();
System.exit(-2);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Set true the MaskFormatter 'commitOnEdit' property.
###@###.### 2005-04-18 05:48:50 GMT
142 is EOSL and at this point of time we will only be fixing critical customer reported issues in this release train. This bug is a P3 webbug on 142 train reported 6 yrs back. So I am closing it out. Reopen later if a customer demands a fix.
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
SunOS grovss37 5.8 Generic_108528-29 sun4u sparc SUNW,Ultra-5_10
A DESCRIPTION OF THE PROBLEM :
If a JFormattedTextField is constructed with a javax.swing.text.MaskFormatter
and a 'PERSIST' or 'COMMIT' focus lost behavior is used, the currently edited value is
always considered as valid when it's incomplete.
This problem does not exist when the MaskFormatter 'commitOnEdit' property is true.
This is due to the 'run()' method in JFormattedTextField.FocusLostHandler class.
In the case of 'PERSIST' or 'COMMIT' focus lost behavior, it does not update 'editValid'.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Launch the test case and type only one valid character (digit) then click the 'Verify' button
to see the value of 'editValid'.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.BorderFactory;
import javax.swing.WindowConstants;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.Box;
import javax.swing.text.MaskFormatter;
import java.text.ParseException;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;
public class FormattedTextTest extends JFrame
{
public FormattedTextTest() {
super("FormattedTextTest");
// Create a mask.
MaskFormatter formatter = null;
try {
formatter = new MaskFormatter("##$##");
}
catch (ParseException e) {
e.printStackTrace();
System.exit(-1);
}
formatter.setPlaceholderCharacter('_');
//formatter.setCommitsOnValidEdit(true);
// Create a formatted text field.
final JFormattedTextField ftf = new JFormattedTextField(formatter);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
//ftf.setFocusLostBehavior(JFormattedTextField.COMMIT);
ftf.setMaximumSize(ftf.getPreferredSize());
ftf.setMinimumSize(ftf.getPreferredSize());
// Create a label.
JLabel label = new JLabel("Price : ");
label.setLabelFor(ftf);
// Create a panel.
Box pan = Box.createHorizontalBox();
pan.add(label);
pan.add(ftf);
// Create a button.
JButton button = new JButton("Verify");
//button.setMargin(new Insets(0,0,0,0));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Edit valid : " + ftf.isEditValid());
Toolkit.getDefaultToolkit().beep();
}
});
JPanel contentPane = new JPanel();
BoxLayout box = new BoxLayout(contentPane, BoxLayout.Y_AXIS);
contentPane.setLayout(box);
contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
contentPane.add(pan);
contentPane.add(Box.createVerticalStrut(10));
contentPane.add(button);
setContentPane(contentPane);
}
public static void main(String[] args) {
try {
JFrame frame = new FormattedTextTest();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
catch (Exception e) {
e.printStackTrace();
System.exit(-2);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Set true the MaskFormatter 'commitOnEdit' property.
###@###.### 2005-04-18 05:48:50 GMT
142 is EOSL and at this point of time we will only be fixing critical customer reported issues in this release train. This bug is a P3 webbug on 142 train reported 6 yrs back. So I am closing it out. Reopen later if a customer demands a fix.
- relates to
-
JDK-6256410 JFormattedTextField looses its mask if using setValue on an invalid value
-
- Closed
-