aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable Validation Example Needed Here? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Validation Example Needed Here?" Watch "JTable Validation Example Needed Here?" New topic
Author

JTable Validation Example Needed Here?

mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
hi there
iam new to jtable
and i want simple example of jtable consists of 3 columns
name,number,price first is string and second and third are integer
and if the user tries to enter non numeric values in the second or in the third error message appear
and if the second column contains cell with 0 value the whole row is colored as red???
can anyone help please?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
where are you stuck?
(post what you've tried)
mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
here's what i did
i have two integer columns Number,Price
and i made them accept only integers
but i can't handle how to make the cell regain focus
when the user enter invalid value(When The Error Message Appear)




Karthick Dharani Vidhya
Ranch Hand

Joined: Feb 23, 2008
Posts: 89
Hi,

Override the editingStopped(ChangeEvent e) method in JTable.

Try by moving the validation part [converting to integer and catching the exception]to this overridden method. If the exception id thrown then just return from the method. By doing so the cell will still be in editing mode with that value that was entered. sample code is




NOTE: Try setting the document to the textfields by which you can prevent the users typing other than integers in 2nd and 3rd column.


Karthick D V
mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
hi thank you for your sample
but iam really so new to JTable
and i really can't figure that out
when i try to use your code it give me exception




mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
any one help me please?
mahmoud saleh
Greenhorn

Joined: Sep 06, 2008
Posts: 19
i just want that in the first code i posted
when NumberFormatException Occurs The Focus Returns Back To The Cell
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable Validation Example Needed Here?