Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

java - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...