Как изменить фон для всего столбца и всей строки выбранной ячейки - PullRequest
0 голосов
/ 29 октября 2011

У меня есть jtable, и я хочу, чтобы при выборе ячейки изменить фон для всей строки и всего столбца этой ячейки (не только для изменения фона ячейки!), Как это сделать?

пожалуйста, сообщите, спасибо.

1 Ответ

3 голосов
/ 29 октября 2011

Я использовал следующее, чтобы контролировать цвет столбца. Чтобы увидеть, как включить текущую ячейку, посмотрите на http://www.javaworld.com/javaworld/javaqa/2001-09/03-qa-0928-jtable.html

    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;
        }
    };
...