Here you can find the source of setBackgroundColor(final Component comp, final JTable table, boolean isSelected)
Parameter | Description |
---|---|
comp | the renderer component to change. |
table | its table. |
isSelected | if the cell is selected. |
comp
.
public static Component setBackgroundColor(final Component comp, final JTable table, boolean isSelected)
//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; } }