• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField to take Integer values  RSS feed

 
Sri Rangan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to creat a JTextField which takes Integer values? Can I make use of JIntegerTextField??
I need this to add to my TableCellEditor. When an Integer value on a JTable cell is edited, it is changed to String value. But I need to get the value as Integer.
Thanks
Sri
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a class called a Document class that can make JTextFields only a certain type, or only allow certain value(s) in it. Here is an example of an Integer one that I had made.
Here is the NumberTextField that I made


and here is the NumericDocument class

And now the code to create one of these gems.

The first 3 is for the number of columns of the TextField. the second 3 is the length of the allowed enterable entry for instance in my positive only TextField the possible range of values is 0 - 999.
Hope that helps.
Mark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!