JFormattedTextField not retaining input.
From: Stuart Leonard (suncds_at_earthlink.net)
Date: 05/29/04
- Next message: SZDev - Slash: "Re: File organization - RULES OF THUMB"
- Previous message: Hung Huynh: "Re: Swing, tail -f and threading"
- Next in thread: Gerard H. Pille: "Re: JFormattedTextField not retaining input."
- Reply: Gerard H. Pille: "Re: JFormattedTextField not retaining input."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 May 2004 17:03:31 GMT
When I enter keyboard input into the JFormattedTextField object, the input
is not being retained when the field has lost focus.
I am using SDK/JRE 1.4.0, Windows XP Professional.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.text.MaskFormatter;
import java.text.ParseException;
public class TestFrame extends JFrame
{
public JFormattedTextField low;
public JFormattedTextField high;
public JFormattedTextField incr;
public TestFrame() {
JPanel panel = new JPanel(new BorderLayout());
// add selection panel
MaskFormatter mf1 = null;
MaskFormatter mf2 = null;
try
{
mf1 = new MaskFormatter("####");
mf1.setPlaceholderCharacter('_');
mf2 = new MaskFormatter("###");
mf2.setPlaceholderCharacter('_');
}
catch (ParseException e){
}
low = new JFormattedTextField(mf1);
high = new JFormattedTextField(mf1);
incr = new JFormattedTextField(mf2);
JPanel select = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.NONE;
addgbc(select, new JLabel("Low Temperature Range . . ."),gbc,0,0);
addgbc(select, low,gbc,1,0);
addgbc(select, new JLabel("High Temperature Range . ."),gbc,0,1);
addgbc(select, high,gbc,1,1);
addgbc(select, new JLabel("Increment Degrees . . . . ."),gbc,0,2);
addgbc(select, incr,gbc,1,2);
panel.add(select, BorderLayout.NORTH);
JFrame frame = new JFrame("Test JFormattedTextField");
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(panel, BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
}
private void addgbc(Container cont, JComponent comp, GridBagConstraints
gbc, int x, int y) {
gbc.gridx=x; gbc.gridy=y;
cont.add(comp,gbc);
}
public static void main (String[] args) {
new TestFrame();
}
}
- Next message: SZDev - Slash: "Re: File organization - RULES OF THUMB"
- Previous message: Hung Huynh: "Re: Swing, tail -f and threading"
- Next in thread: Gerard H. Pille: "Re: JFormattedTextField not retaining input."
- Reply: Gerard H. Pille: "Re: JFormattedTextField not retaining input."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]