Java JTable Header setHeaderIcon(JTable table, final int column, final ImageIcon icon)

Here you can find the source of setHeaderIcon(JTable table, final int column, final ImageIcon icon)

Description

set Header Icon

License

LGPL

Declaration

public static void setHeaderIcon(JTable table, final int column, final ImageIcon icon) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import javax.swing.*;

import java.awt.*;

import javax.swing.table.DefaultTableCellRenderer;

import javax.swing.table.TableCellRenderer;

public class Main {
    public static void setHeaderIcon(JTable table, final int column, final ImageIcon icon) {
        final TableCellRenderer orig = table.getTableHeader().getDefaultRenderer();
        table.getTableHeader().getColumnModel().getColumn(column).setHeaderRenderer(new DefaultTableCellRenderer() {
            @Override//from w w w  .ja v a 2 s .c  om
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
                JLabel com = (JLabel) orig.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
                        column);
                com.setHorizontalAlignment(JLabel.LEADING); // On Fedora its TRAILING; looks odd with the icon itself trailing
                com.setIcon(icon);
                return com;
            }
        });
    }
}

Related

  1. makeHeaderFillEmptySpace(JTable table)
  2. makeTableHeadersCentered(final JTable table, final boolean dataColsAlso)
  3. modifyTableHeader(JTableHeader head, Vector columnNames)
  4. paintHeader(Graphics graphics, JTable table, int x, int width)
  5. removeBadChars(JTable table, boolean skipHeaderBoolean)
  6. setOptimalHeaderWidth(int col)
  7. setPressedColumn(JTableHeader tableHeader, int columnModelIndex)
  8. setTableHeaderCellRenderer(TableColumn tableCol)
  9. setupAsRowHeader(final JTable table)