1 /* 2 * Copyright (c) 2003-2008 by Cosylab d. d. 3 * 4 * This file is part of CosyBeans-Common. 5 * 6 * CosyBeans-Common is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * CosyBeans-Common is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with CosyBeans-Common. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package com.cosylab.gui.components.table.renderers; 21 22 import java.awt.Component; 23 24 import javax.swing.JLabel; 25 import javax.swing.JTable; 26 import javax.swing.table.TableCellRenderer; 27 28 /** 29 * This renderer is used to display cells whose contents are null. It accepts no 30 * parameters an is rendered as a blank cell. Purpose of this class is to 31 * simplify drawing of cells when there could be null contents in the 32 * TableModel. 33 * 34 * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a> 35 * @version $id$ 36 */ 37 public class EmptyCellRenderer extends JLabel implements TableCellRenderer { 38 39 private static final long serialVersionUID = 1L; 40 /** 41 * Default constructor for EmptyCellRenderer. 42 */ 43 public EmptyCellRenderer() { 44 setOpaque(true); 45 } 46 47 /* 48 * (non-Javadoc) 49 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) 50 */ 51 public Component getTableCellRendererComponent( 52 JTable table, 53 Object cell, 54 boolean isSelected, 55 boolean hasFocus, 56 int row, 57 int column) { 58 59 if (isSelected) { 60 setBackground(table.getSelectionBackground()); 61 setForeground(table.getSelectionForeground()); 62 } else { 63 setBackground(table.getBackground()); 64 setForeground(table.getForeground()); 65 } 66 67 68 return this; 69 } 70 71 }