Java JTable Header paintHeader(Graphics graphics, JTable table, int x, int width)

Here you can find the source of paintHeader(Graphics graphics, JTable table, int x, int width)

Description

Paints the given JTable's table default header background at given x for the given width.

License

Open Source License

Parameter

Parameter Description
graphics the Graphics to paint into.
table the table that the header belongs to.
x the x coordinate of the table header.
width the width of the table header.

Declaration

public static void paintHeader(Graphics graphics, JTable table, int x, int width) 

Method Source Code


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

import java.awt.Component;
import java.awt.Graphics;
import javax.swing.CellRendererPane;
import javax.swing.JComponent;
import javax.swing.JTable;

import javax.swing.table.TableCellRenderer;

public class Main {
    private static final CellRendererPane CELL_RENDER_PANE = new CellRendererPane();

    /**/* w ww. j av a 2 s.c  o m*/
     * Paints the given JTable's table default header background at given
     * x for the given width.
     *
     * @param graphics the {@link Graphics} to paint into.
     * @param table    the table that the header belongs to.
     * @param x        the x coordinate of the table header.
     * @param width    the width of the table header.
     */
    public static void paintHeader(Graphics graphics, JTable table, int x, int width) {
        TableCellRenderer renderer = table.getTableHeader().getDefaultRenderer();
        Component component = renderer.getTableCellRendererComponent(table, "", false, false, -1,
                table.getColumnCount());

        component.setBounds(0, 0, width, table.getTableHeader().getHeight());

        ((JComponent) component).setOpaque(false);
        CELL_RENDER_PANE.paintComponent(graphics, component, null, x, 0, width, table.getTableHeader().getHeight(),
                true);
    }
}

Related

  1. isRowHeaderVisible(JTable table)
  2. layoutHeaders(JTable p_Table)
  3. makeHeaderFillEmptySpace(JTable table)
  4. makeTableHeadersCentered(final JTable table, final boolean dataColsAlso)
  5. modifyTableHeader(JTableHeader head, Vector columnNames)
  6. removeBadChars(JTable table, boolean skipHeaderBoolean)
  7. setHeaderIcon(JTable table, final int column, final ImageIcon icon)
  8. setOptimalHeaderWidth(int col)
  9. setPressedColumn(JTableHeader tableHeader, int columnModelIndex)