Solved

JFormattedTextField, NumberFormatter etc.

Posted on 2003-12-11
3
316 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now