Here you can find the source of paintHeader(Graphics graphics, JTable table, int x, int width)
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. |
public static void paintHeader(Graphics graphics, JTable table, int x, int width)
//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); } }