具有布尔数据类型的JTable单元

时间:2016-03-22 07:16:13

标签: java swing jtable

在我的Jtable我有一个boolean个值显示为Checkbox的列。我添加了Jtable TableCellRenderer,以下是代码:

TableCellRenderer tableCellBoolean = new DefaultTableCellRenderer() {
        Boolean UserEnterValuse = new Boolean(false);

        public Component getTableCellRendererComponent(JTable table,
                Boolean value, boolean isSelected, boolean hasFocus,
                int row, int column) {
            if (value instanceof Boolean) {
                UserEnterValuse = Boolean.valueOf(value.toString());
                System.out.print(table.getCellRenderer(row, column));
                //InstallmentDate.get
                table.setValueAt(UserEnterValuse, row, column);

            }
            return super.getTableCellRendererComponent(table, value, isSelected,
                    hasFocus, row, column);
        }
    };

我还添加了setCellEditor,但是当我点击Jtable单元格时,它会显示Checkbox,在选择或更改单元格中的值后,它会显示为true或false取决于选择类型,但不会显示Checkbox

如果我没有添加TableCellRenderer,当我将值设置为Jtable单元格时,它会给我一个错误:Object can not cast to Boolean Type

0 个答案:

没有答案