Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何更改选定单元格整列和整行的背景_Java_Swing_Jtable_Tablecellrenderer - Fatal编程技术网

Java 如何更改选定单元格整列和整行的背景

Java 如何更改选定单元格整列和整行的背景,java,swing,jtable,tablecellrenderer,Java,Swing,Jtable,Tablecellrenderer,我有一个jtable,我想在选择一个单元格时更改该单元格整行和整列的背景(不是仅更改单元格的背景!),如何操作 请告知,谢谢。我使用了以下方法来控制列的颜色。要查看如何合并当前单元格,请查看 我使用了以下方法来控制列的颜色。要查看如何合并当前单元格,请查看 你所说的下列是什么意思公司背景(MyColors.getColor(索引行));公司设置前景(MyColors.getColor(索引行))您需要定义类MyColors,并添加函数getColor(int)。或者,将MyColor.get

我有一个jtable,我想在选择一个单元格时更改该单元格整行和整列的背景(不是仅更改单元格的背景!),如何操作


请告知,谢谢。

我使用了以下方法来控制列的颜色。要查看如何合并当前单元格,请查看


我使用了以下方法来控制列的颜色。要查看如何合并当前单元格,请查看


你所说的下列是什么意思<代码>公司背景(MyColors.getColor(索引行));公司设置前景(MyColors.getColor(索引行))您需要定义类MyColors,并添加函数getColor(int)。或者,将MyColor.getColor(…)替换为类似Color colors[]={Color.black、Color.blue、Color.cyan、Color.darkGray、Color.gray、Color.green、Color.magenta、Color.orange、Color.pink、Color.red、Color.yellow}的数组;你所说的下列是什么意思<代码>公司背景(MyColors.getColor(索引行));公司设置前景(MyColors.getColor(索引行))您需要定义类MyColors,并添加函数getColor(int)。或者,将MyColor.getColor(…)替换为类似Color colors[]={Color.black、Color.blue、Color.cyan、Color.darkGray、Color.gray、Color.green、Color.magenta、Color.orange、Color.pink、Color.red、Color.yellow}的数组;
    this.table = new JTable()
    {
        private static final long serialVersionUID = -5739534894469353266L;


        /**
         * Set the background color of the row equal to the color of the path in the map
         */
        @Override
        public Component prepareRenderer( final TableCellRenderer renderer, final int Index_row, final int Index_col )
        {
            final Component comp = super.prepareRenderer( renderer, Index_row, Index_col );
            // even index, selected or not selected

            if ( Index_col == 1 )
            {
                // Color column, match foreground / background colors
                comp.setBackground( MyColors.getColor( Index_row ) );
                comp.setForeground( MyColors.getColor( Index_row ) );
            }
            else
            {
                comp.setBackground( Color.white );
                comp.setForeground( Color.black );
            }
            return comp;
        }
    };