JFormattedTextField / Formatter / OverWriteMode
Hi *
i am struggeling with a behavior of the JFormattedTextField
See example. If i type in 4 digits number values it works.
The cursor position is after the 4. digit.
If i type more numbers they will be overwritten from right to left.
I do not want this behavior.
I thought setting OverWriteMode to false should stop this, but it does not work.
Any ideas ?.
Many Thanx
Ralph
Code:
public class JFormattedTF extends JFrame {
public JFormattedTF() {
JPanel panel = new JPanel();
JLabel label = new JLabel("Number Format :");
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumIntegerDigits(4);
nf.setGroupingUsed(false);
NumberFormatter formatter = new NumberFormatter(nf);
formatter.setAllowsInvalid(false);
formatter.setOverwriteMode(false);
JFormattedTextField tf = new JFormattedTextField(
formatter);
tf.setColumns(10);
tf.setHorizontalAlignment(JTextField.LEFT);
panel.add(label);
panel.add(tf);
getContentPane().add(panel, BorderLayout.SOUTH);
pack();
}
public static void main(String[] args) {
JFormattedTF tfe = new JFormattedTF();
tfe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tfe.setVisible(true);
}
}