为某些行设置jtable前景色

时间:2013-06-11 11:01:04

标签: java swing jtable renderer

我创建了一些costum单元格渲染来改变我的jtable的外观,我改变了一些行的颜色和字体,我试图做同样但它不起作用,这是我的代码:

@Override
            public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                Component c = super.prepareRenderer(renderer, row, column);
                int firstRow = 0;
                int lastRow = jTable1.getRowCount() - 1;
                if (row == lastRow) {
                    ((JComponent) c).setBackground(new Color(218, 244, 247));
                //((JComponent) c).setFont(new java.awt.Font("Tahoma", 1, 12));
                } else if (row == firstRow) {
                    ((JComponent) c).setBackground(new Color(218, 244, 247));
                    ((JComponent) c).setFont(new java.awt.Font("Tahoma", 1, 12));
                     ((JComponent) c).setForeground(new Color(11, 114, 126));
                } else if (row == 5) {
                    ((JComponent) c).setBackground(new Color(218, 244, 247));
                    ((JComponent) c).setFont(new java.awt.Font("Tahoma", 1, 12));
                } else {
                    ((JComponent) c).setBackground(jTable1.getBackground());
                }

                return c;
            }

这是我遇到问题的时候:

((JComponent)c)。setForeground(new Color(11,114,126));

if (row == firstRow) {
((JComponent) c).setBackground(new Color(218, 244, 247));
((JComponent) c).setFont(new java.awt.Font("Tahoma", 1, 12));
((JComponent) c).setForeground(new Color(11, 114, 126));}

由于

1 个答案:

答案 0 :(得分:1)

  

,我改变了一些行的颜色和字体,我试着这样做但是   它不起作用,这是我的代码: