Java JTable Cell Renderer createDefaultTableCellRenderer()

Here you can find the source of createDefaultTableCellRenderer()

Description

create Default Table Cell Renderer

License

Open Source License

Declaration

private static DefaultTableCellRenderer createDefaultTableCellRenderer() 

Method Source Code

//package com.java2s;

import java.awt.Component;

import javax.swing.JLabel;

import javax.swing.JTable;

import javax.swing.UIManager;

import javax.swing.table.DefaultTableCellRenderer;

import javax.swing.table.JTableHeader;

public class Main {
    private static DefaultTableCellRenderer createDefaultTableCellRenderer() {
        DefaultTableCellRenderer label = new DefaultTableCellRenderer() {
            private static final long serialVersionUID = 1L;

            public Component getTableCellRendererComponent(JTable table,
                    Object value, boolean isSelected, boolean hasFocus,
                    int row, int column) {
                if (table != null) {
                    JTableHeader header = table.getTableHeader();
                    if (header != null) {
                        setForeground(header.getForeground());
                        setBackground(header.getBackground());
                        setFont(header.getFont());
                    }/* w ww  .jav  a  2  s.  c om*/
                }

                setText((value == null) ? "" : value.toString());
                setBorder(UIManager.getBorder("TableHeader.cellBorder"));
                return this;
            }
        };
        label.setHorizontalAlignment(JLabel.CENTER);
        return label;
    }
}

Related

  1. adaptToTable(final JComponent renderer, final JTable table, boolean isSelected, final boolean hasFocus, final int row, final int column)
  2. applyRenderers(final JTable table, final TableCellRenderer[] renderers)
  3. applyRenderers(final JTable table, final TableCellRenderer[] renderers)
  4. configureColumn(JTable table, int columnNumber, Integer width, TableCellRenderer renderer, TableCellEditor editor)
  5. getCellRenderer(final int hMargin)
  6. getDefaultRenderer(JTable table, TableColumn column)
  7. getTableCellRendererClass( Class propType)
  8. setCellRender(JTable table, int columnIdx, TableCellRenderer render)