为什么JTable中的布尔值显示为true/false而不是复选框? [英] Why is a boolean value in JTable showing as true/false instead of a checkbox?

查看:92
本文介绍了为什么JTable中的布尔值显示为true/false而不是复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的布尔值不应该显示为复选框吗?它显示为一个真/假字符串值.这就是我填充数据的方式:

Shouldn't the new Boolean appear as a checkbox? It's showing up as a true/false string value instead. This is how I'm populating the data:

    Object[] columnNames4 = {"Name", "City", "Checkbox"};
    Object[][] data = {
    {"john smith",
     "x", new Boolean(false)},
    {"jenny m",
     "y", new Boolean(false)}
     };
    JTable table4 = new JTable(data, columnNames4);
    JScrollPane S3 = new JScrollPane(table4);
    S3.setPreferredSize(new Dimension(300, 300));

推荐答案

创建

Create a subclass ofAbstractTableModel and return Boolean.class in the Method getColumnClass() for the column you want.

这篇关于为什么JTable中的布尔值显示为true/false而不是复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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