File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Head First Android 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: 20048
    
  30

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 - OCEJPAD 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: 20048
    
  30

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?

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jtable
 
jQuery in Action, 3rd edition