Article View: borland.public.jbuilder.java.swing
Article #314Inconsistent Masking in JFormattedTextField?
From: prunesquallor
Date: Tue, 09 Aug 2005 13:28
Date: Tue, 09 Aug 2005 13:28
58 lines
3468 bytes
3468 bytes
Is this a bug or am I missing something? I did the following in JB2005:
1. Created a simple application with just a content pane.
2. Added a JFormattedTextField with a mask. Code looks as so:
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Field Problem");
MaskFormatter msk = new MaskFormatter("#");
JFormattedTextField jFormattedTextField1 = new
JFormattedTextField(msk);
jFormattedTextField1.setFont(new java.awt.Font("SansSerif",
Font.BOLD,28));
jFormattedTextField1.setText("0");
jFormattedTextField1.setBounds(new Rectangle(142, 119, 60, 30));
contentPane.add(jFormattedTextField1);
}
3. Ran the above. Application worked, with a largeish field that only allows
one number to be entered.
4. Added a second field - code looks as so:
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 300));
setTitle("Field Problem");
MaskFormatter msk = new MaskFormatter("#");
JFormattedTextField jFormattedTextField1 = new
JFormattedTextField(msk);
jFormattedTextField1.setFont(new java.awt.Font("SansSerif",
Font.BOLD,28));
jFormattedTextField1.setText("0");
jFormattedTextField1.setBounds(new Rectangle(142, 119, 60, 30));
contentPane.add(jFormattedTextField1);
JFormattedTextField jFormattedTextField2 = new
JFormattedTextField(msk);
jFormattedTextField2.setFont(new java.awt.Font("SansSerif",
Font.BOLD,28));
jFormattedTextField2.setText("0");
jFormattedTextField2.setBounds(new Rectangle(1, 1, 60, 30));
contentPane.add(jFormattedTextField2);
}
5. System now places me on the jFormattedTextField2 when I run the
application. If I immediately tab to the other field, and start entering
data, then the mask is completely ignored in the other field
(jFormattedTextField1). If I the exit and return to the field, the mask
suddenly starts working!
Am I doing something completely dumb? Note that this came up because I was
trying to set up an array of jFormattedTextFields, and found that the masks
were inconsistently applied!
ATB
John B
Technical Details
Message-ID:
<42f8af23@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!news.usenetserver.com!atl-c07.usenetserver.com!news.usenetserver.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 111d45,c6aaf7682a279724,start X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit From: "prunesquallor" <prunesquallor@proproco.co.uk> Newsgroups: borland.public.jbuilder.java.swing Subject: Inconsistent Masking in JFormattedTextField? Date: Tue, 9 Aug 2005 14:28:03 +0100 Lines: 60 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 NNTP-Posting-Host: 213.208.127.201 Message-ID: <42f8af23@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1123594019 213.208.127.201 (9 Aug 2005 06:26:59 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!news.usenetserver.com!atl-c07.usenetserver.com!news.usenetserver.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail