删除jtable中的单元格边框 [英] remove cells border in a jtable

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

问题描述

我有我的自定义单元格渲染器,并希望删除单元格的边框。

我该怎么办?我尝试了setBorder,但它不起作用。

I have my on custom cell renderer and want to remove the border of the cell.
How can i do it? I tried setBorder but it doesn't work.

这是我的渲染器代码:

public class MyTableCellRenderer extends DefaultTableCellRenderer {

    private static final long serialVersionUID = -1195682136616306875L;

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        Component c = super.getTableCellRendererComponent(table, value,
                isSelected, hasFocus, row, column);
        if (!isSelected) {
            if (row % 2 == 0 && row != 1) {
                c.setBackground(new Color(255, 255, 150));
            } else {
                c.setBackground(Color.WHITE);
            }
        } else {
            c.setBackground(new Color(255, 230, 255));
        }
        c.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        return c;
    }
}


推荐答案

细胞之间绘制的线不是细胞本身的一部分。他们被桌子绘制。您可以使用以下命令关闭整个表:

The lines drawn between cells are not part of the cells themselves. They are drawn by the table. You can turn them off for the entire table with:

table.setShowGrid(false);

要仅禁用水平线或仅垂直线:

To disable just the the horizontal or just the vertical lines:

table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);

或者,你可以改变行的颜色:

Or, you can change the color of the lines with:

table.setGridColor(color)

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

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