Java JTable Cell Renderer setUpCellRenderer(JTable table)

Here you can find the source of setUpCellRenderer(JTable table)

Description

set Up Cell Renderer

License

Open Source License

Declaration

public static void setUpCellRenderer(JTable table) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

import javax.swing.BorderFactory;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;

public class Main {
    public static void setUpCellRenderer(JTable table) {
        DefaultTableCellRenderer r = new DefaultTableCellRenderer() {
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
                Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
                        column);/*from w w w .j a  v  a 2s. com*/
                setBorder(BorderFactory.createEtchedBorder());
                return renderer;
            }
        };
        int colCount = table.getColumnCount();
        for (int i = 0; i < colCount; i++) {
            TableColumn col = table.getColumnModel().getColumn(i);
            col.setCellRenderer(r);
        }
    }
}

Related

  1. getCellRenderer(final int hMargin)
  2. getDefaultRenderer(JTable table, TableColumn column)
  3. getTableCellRendererClass( Class propType)
  4. setCellRender(JTable table, int columnIdx, TableCellRenderer render)
  5. setTableRenderer(JTable table, Integer alignment)