[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

JFormattedTextField, NumberFormatter etc.

Does anyone know how to set a formatter object on a JFormattedTextField (JFTF) *AFTER* it's created?? (without subclassing it?)

The JFTF is being constructed from an XML file parsed with a SAX parser; the way I implemented it, I really need (want) to call the default constructor in one method, and set it's attributes with another.

I can get the JFTF to work if I set the formatter in the constructor, but I simply don't have the attributes handy when I'm constructing it.

Well, actually I do, but I can use a really sweet algorithm if I could set the attributes after the JFTF is constructed.

setFormatter() is protected; JFormattedTextField.AbstractFormatter.install() isn't what I thought it was...  The documentation is surprisingly limited, and I have yet to find an example where they don't set the formatter in the constructor.

Thanks,

Shawn
0
ShawnCurry
Asked:
ShawnCurry
  • 2
1 Solution
 
objectsCommented:
try setting the formatter factory.
0
 
ShawnCurryAuthor Commented:
Yup..  got it.. I'm really appreciating the open source..  Just had to figure out how it works...

JFormattedTextField ftf = new JFormattedTextField();
DefaultFormatterFactory df = new DefaultFormatterFactory(
      new NumberFormatter( NumberFormat.getIntegerInstance()));
ftf.setFormatterFactory(df);

That's a heck of a wrapper... Oh well..

Thanks again.
0
 
objectsCommented:
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now