Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cell validation in JTable

I have a JTable that needs cell validation for the cells where the user can input text. When a user enters invalid text the border of the cell turns red.

I've managed to get this working associating a two dimension array to flag if each cell has errors or not.

The problem is that the user must be able to reorder the table (by column). I have to store the error flag in the table model, not separatly. Anyone has ideas how to do this?

like image 391
xgon Avatar asked Apr 25 '13 21:04

xgon


1 Answers

Also consider a custom TableCellEditor, seen here and below. Adding an InputVerifier, as shown here, is a good alternative.

As the user must be able to reorder the table by column:

JTable provides methods that convert from model coordinates to view coordinates — convertColumnIndexToView and convertRowIndexToView — and that convert from view coordinates to model coordinates — convertColumnIndexToModel and convertRowIndexToModel.

image

like image 192
trashgod Avatar answered Sep 28 '22 15:09

trashgod