Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable Validation Example Needed Here?

 
mahmoud saleh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where are you stuck?
(post what you've tried)
 
mahmoud saleh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mahmoud saleh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any one help me please?
 
mahmoud saleh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i just want that in the first code i posted
when NumberFormatException Occurs The Focus Returns Back To The Cell
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic