Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JTable Validation Example Needed Here?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)




 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any one help me please?
 
mahmoud saleh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic