General discussion


JTable cell action validation

By Shepps ·

I have a JTable where two of the columns contain min and max numbers defining a range.

What I would like to do is this: whenever a new row is inserted and a value is entered into either the max or min column I would like to check to see ifthe this number falls between the min and max range of ANY of the other rows in the JTable. If so, pop up a message telling the user to enter another value.

What should I be using? CellEditors? or would some other type of event handling on the table be more appropriate?


Philip Sheppard

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

JTable cell action validation

by okujava In reply to JTable cell action valida ...

you should write a subclass of AbstractTableModel, override the
public void setValueAt(Object aValue,int rowIndex,int columnIndex) method and set an instance of the class as a model of your jtable. In the method is aValue an object of String (if you use the default cell editor of course). you can now parse the string and check the value...

Collapse -

JTable cell action validation

by Shepps In reply to JTable cell action valida ...

Unfortunately I can only rate this as 'unacceptable' although that is not quite true! I took this new approach into account and found that it would not suit me too much in my case (accessing the TableModel was not quite possible in my class). In theend I went with neither. I did a check of the entire table when the update table button was pressed. I used a CellEditor for simple things like range checking.

Thanks for reply!

Related Discussions

Related Forums