JTable中的单元验证 [英] Cell validation in JTable

查看:106
本文介绍了JTable中的单元验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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?

推荐答案

还要考虑自定义 TableCellEditor ,见此处及以下。添加 InputVerifier ,如此处所示,是一个不错的选择。

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 提供从模型坐标转换为视图坐标的方法 - convertColumnIndexToView convertRowIndexToView - 并且从视图坐标转换为模型坐标 - convertColumnIndexToModel convertRowIndexToModel

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.

这篇关于JTable中的单元验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆