• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JFormattedTextField  RSS feed

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java 1.4 has a new component, JFormattedTextField, which allows formats, masks, etc., to be specified for a text field. Handy for phone number, ssn, numeric entry. I'm trying to use this in a program, and it needs to be declared as an instance variable, here's the code:
protected JFormattedTextField ftf = new JFormattedTextField( new MaskFormatter("###-##-####"));
When I compile it says that MaskFormatter throws ParseException. How do I catch or throw an exception while declaring an instance variable? Is this a dumb question? It seems like it must be obvious, but I don't see it.
Thanks,
Debra Bellmaine
SCJP2
 
Debra Bellmaine
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to resolve this by splitting up the variable declaration and putting the actual variable assignment in a method called by the constructor, inside a try/catch.
Debra
SCJP2
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!