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

jtable

 
jonathan benz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a table with 5 columns. I was required to validate column 3 and 5 for numeric input.

I could validate numeric cell by cell.
If I do that, I need to write the code for each cell.

Please suggest how I can iterate the column 3 and 5 for the validation
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just use a TableModel implementation (often a (anonymous) DefaultTableModel subclass) that overrides getColumnClass to return Integer.class for columns 3 and 5. JTable has built-in support for numbers, so there will be validation upon input.
 
jonathan benz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Rob

Here i would like to display a JOptionMessageDialog message for non-numeric value for column 1 and 2 only

 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to display a dialog? The red border you get now is much less intrusive.
 
jonathan benz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Rob.

I need to popup an alert message for the user to key-in numeric values.
This system is a questionnaire targeting for the public to give their feedback.

So, it will be more informed if the system prompt an alert message rather than the red line.

please help how can i make an alert instead the red bolder?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic