This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Input from JFormattedTextField  RSS feed

 
Maya Naga
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranches,

i am creating a simple program to get input from user and do calculation....
Am using netbeans... when i try to get input from textfield am getting numberformatexception..

here is my sample code..



can any please help me?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a possiblity of an NumberFormatException. It depends that the text of the field was.
I think you should be able to solve it with this code:
 
Bartek Myszkowski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't You use getValue() instead of getText() ?? It always returns valid value and getText may not... also use JFormattedTextField(Object value) constructor to create first valid value and setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0")))); to get integers only.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!