• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFormattedTextField

 
Debra Bellmaine
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!