Solved

JFormattedTextField, NumberFormatter etc.

Posted on 2003-12-11
3
351 Views
Last Modified: 2010-08-05
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
Comment
Question by:ShawnCurry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 9925719
try setting the formatter factory.
0
 
LVL 3

Author Comment

by:ShawnCurry
ID: 9925799
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
 
LVL 92

Expert Comment

by:objects
ID: 9925828
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question