使用setColor(Color color)方法

解决方案 »

  1.   

    DefaultTableCellRenderer cellRender = new DefaultTableCellRenderer() {
                public Component getTableCellRendererComponent(JTable table,
                        Object value, boolean isSelected, boolean hasFocus,
                        int row, int column) {                this.setHorizontalAlignment(JLabel.RIGHT);                if (row == 0) { //如果是表示星期的单元格
                        this.setBackground(Color.GRAY);
                        //如果是表示今天的单元格
                    } else if (value != null && ((String) value).equals("" + day)) {
                        this.setBackground(Color.PINK);
                    } else { //其余的单元格
                        this.setBackground(Color.WHITE);
                    }                return super.getTableCellRendererComponent(table, value,
                            isSelected, hasFocus, row, column);
                }
            };
    calendar.setDefaultRenderer(Object.class, cellRender);//不要忘了这个。
    大概意思就是,自己写一个方法绘制表格的各个地方,然后再让需要绘制的表格设置这个绘制方法
    相信这个方法可以给你一些提示.这个是绘制一个日历的完整方法.
      

  2.   

    首先, 我的对象是table , 不是jtable。 还有, 我只需要设置表头的字体颜色, “表头”。
    谢谢各位。
      

  3.   

    首先, 我的对象是table , 不是jtable有Table类吗?最后用的还是JTable吧!用这个类DefaultTableCellRenderer 是可以的
      

  4.   

    楼上的:
    import org.eclipse.swt.widgets.Table;用的是swt控件! eclipse 开发。