-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
1.4.2
-
x86
-
windows_2000
FULL PRODUCT VERSION :
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
MaskFormatter setOverwriteMode(false) does not work.
I need to set mask eg. "**************" or "######" etc
and at the same time be able to allow the insert mode so that the characters/numbers fall off the right edge if the field is filled completely and the cusrsor is anywher but at rightmost end of the field.
As per the documentation of setOverwriteMode(int) it must be possible to switch between insert/replace mode but only setOverwriteMode(true) seems to work and setOverwriteMode(false) seems to render the MaskFormatter completly useless.
Debugging through the code I noticed that stringToValue(String, boolean) calls getInvalidOffset(value, completeMatch) that performs length test on new string with the formatting character length and it fails the test returning string length as the location of the invalid character which causes the stringToValue to throw ParseException(...). Due to this the MaskFormatter cannot accept any characters type by the user.
The fix would be to check the OverwriteMode and act accordingly.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.ParseException;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.text.DefaultFormatter;
import javax.swing.text.MaskFormatter;
import org.apache.batik.gvt.Mask;
/**
* TODO Document file JFormattedTextFieldDemo.java.
*
* @since Jul 11, 2005
*/
public class JFormattedTextFieldDemo extends JFrame
{
private javax.swing.JPanel jContentPane = null;
private JFormattedTextField jfmtTextField = null;
/**
* This method initializes jfmtTextField
*
* @return javax.swing.JTextField
*/
private JFormattedTextField getJfmtTextField ()
{
if (jfmtTextField == null)
{
try
{
MaskFormatter fmt = new MaskFormatter("************");
fmt.setOverwriteMode(false);
jfmtTextField = new JFormattedTextField(fmt);
}
catch (ParseException e)
{
// TODO Auto-generated catch block
}
}
return jfmtTextField;
}
public static void main (String[] args)
{
JFormattedTextFieldDemo demo = new JFormattedTextFieldDemo();
demo.setVisible(true);
}
/**
* This is the default constructor
*/
public JFormattedTextFieldDemo ()
{
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize ()
{
this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
this.setSize(300, 58);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJContentPane ()
{
if (jContentPane == null)
{
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(new java.awt.BorderLayout());
jContentPane.add(getJfmtTextField(), java.awt.BorderLayout.NORTH);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
---------- END SOURCE ----------
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
MaskFormatter setOverwriteMode(false) does not work.
I need to set mask eg. "**************" or "######" etc
and at the same time be able to allow the insert mode so that the characters/numbers fall off the right edge if the field is filled completely and the cusrsor is anywher but at rightmost end of the field.
As per the documentation of setOverwriteMode(int) it must be possible to switch between insert/replace mode but only setOverwriteMode(true) seems to work and setOverwriteMode(false) seems to render the MaskFormatter completly useless.
Debugging through the code I noticed that stringToValue(String, boolean) calls getInvalidOffset(value, completeMatch) that performs length test on new string with the formatting character length and it fails the test returning string length as the location of the invalid character which causes the stringToValue to throw ParseException(...). Due to this the MaskFormatter cannot accept any characters type by the user.
The fix would be to check the OverwriteMode and act accordingly.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.text.ParseException;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.text.DefaultFormatter;
import javax.swing.text.MaskFormatter;
import org.apache.batik.gvt.Mask;
/**
* TODO Document file JFormattedTextFieldDemo.java.
*
* @since Jul 11, 2005
*/
public class JFormattedTextFieldDemo extends JFrame
{
private javax.swing.JPanel jContentPane = null;
private JFormattedTextField jfmtTextField = null;
/**
* This method initializes jfmtTextField
*
* @return javax.swing.JTextField
*/
private JFormattedTextField getJfmtTextField ()
{
if (jfmtTextField == null)
{
try
{
MaskFormatter fmt = new MaskFormatter("************");
fmt.setOverwriteMode(false);
jfmtTextField = new JFormattedTextField(fmt);
}
catch (ParseException e)
{
// TODO Auto-generated catch block
}
}
return jfmtTextField;
}
public static void main (String[] args)
{
JFormattedTextFieldDemo demo = new JFormattedTextFieldDemo();
demo.setVisible(true);
}
/**
* This is the default constructor
*/
public JFormattedTextFieldDemo ()
{
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize ()
{
this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
this.setSize(300, 58);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJContentPane ()
{
if (jContentPane == null)
{
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(new java.awt.BorderLayout());
jContentPane.add(getJfmtTextField(), java.awt.BorderLayout.NORTH);
}
return jContentPane;
}
} // @jve:decl-index=0:visual-constraint="10,10"
---------- END SOURCE ----------