wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jtable " Watch "jtable " New topic
Author

jtable

jonathan benz
Greenhorn

Joined: Aug 22, 2011
Posts: 11
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

Joined: Oct 27, 2005
Posts: 19656
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jonathan benz
Greenhorn

Joined: Aug 22, 2011
Posts: 11
thanks Rob

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

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Why do you want to display a dialog? The red border you get now is much less intrusive.
jonathan benz
Greenhorn

Joined: Aug 22, 2011
Posts: 11
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?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jtable
 
Similar Threads
JTable Validation Example Needed Here?
poi read some cell err problem
Verify input in jTable except for head row
Problem with a JTable
How to read a Date column from an Excel sheet using Apache POI