Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All,

How to only allow input number into Jtable when edit and check it at between -1000 and 1000 in java application,

I am beginner java so I not yet about evens of Jtable.

I hope that you will help me!

Thanks very much.
Posted
Updated 21-Dec-11 15:44pm
v2

1 solution

How to write a TableModelListener[^]

You might want to read that. There are multiple Listener-Implementations, choose the one that seems to be the right one for you. I can recommend the TableModelListener - but also the FocusListener[^] (focusLost(FocusEvent e) ) might suite your needs.

No matter which one you might choose, you need to validate the entered String. You can parse the entered String and react on the NumberFormatException and set up a switch-condition to limit the range.
 
Share this answer
 
v2
Comments
ngthtra 23-Dec-11 6:36am    
can you give some example code?
I want when user input characters, this value will not display on editor of table, it is same with command return true or false of event KeyPress in DOT NET.
TorstenH. 23-Dec-11 10:38am    
please make a little search on "validate int java" and see the link above for a Listener-implementation. it's no secret, you can read it all in the WWW.

I can also recommend o buy a book, it's got the advantage that you do not need to know any "search engine keywords" to read it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900