문제

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.

Here is my renderer code:

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)

다른 팁

I don't know how your code compiles since only Swing components can have a Border and the Component class doesn't have a setBorder() method.

When I override the default renderer I use something like:

Class CustomRenderer extends DefaultTableCellRenderer
{
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        this.setBorder (BorderFactory.createBevelBorder (EtchedBorder.RAISED));
        return this;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top