Java JTable Color setBackgroundColor(final Component comp, final JTable table, boolean isSelected)

Here you can find the source of setBackgroundColor(final Component comp, final JTable table, boolean isSelected)

Description

Set the background colour from the table.

License

Open Source License

Parameter

Parameter Description
comp the renderer component to change.
table its table.
isSelected if the cell is selected.

Return

comp.

Declaration

public static Component setBackgroundColor(final Component comp, final JTable table, boolean isSelected) 

Method Source Code


//package com.java2s;
/*//from   ww  w.ja v a  2  s  .  c  o  m
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
 * 
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 */

import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;

public class Main {
    /**
     * Set the background colour from the table.
     * 
     * @param comp the renderer component to change.
     * @param table its table.
     * @param isSelected if the cell is selected.
     * @return <code>comp</code>.
     * @see JTable#getBackground()
     * @see JTable#getSelectionBackground()
     */
    public static Component setBackgroundColor(final Component comp, final JTable table, boolean isSelected) {
        return setBackgroundColor(comp, table, isSelected, null);
    }

    protected static Component setBackgroundColor(final Component comp, final JTable table, boolean isSelected,
            Color bgColor) {
        if (isSelected) {
            comp.setBackground(table.getSelectionBackground());
        } else {
            comp.setBackground(bgColor == null ? table.getBackground() : bgColor);
        }
        return comp;
    }
}

Related

  1. getTableBackgroundColor(boolean colored)
  2. getTableGridColor()
  3. possiblyFixGridColor(JTable table)
  4. setColors(final Component comp, final JTable table, boolean isSelected, Color bgColor, Color fgColor)
  5. setForegroundColor(final Component comp, final JTable table, boolean isSelected, Color fgColor)