List of utility methods to do JTable Header
Color | getTableHeaderBackground() get Table Header Background return UIManager.getColor("TableHeader.background"); |
Color | getTableHeaderColor() get Table Header Color return UIManager.getColor("TableHeader.background"); |
String | headerString(JTable t) header String return headerString(t.getColumnModel());
|
boolean | isColumnSelected(JTableHeader tableHeader, int columnModelIndex) true if the given column model index is selected in the given JTableHeader . int selectedColumn = getSelectedColumn(tableHeader); return selectedColumn >= 0 && selectedColumn == columnModelIndex; |
boolean | isRowHeaderVisible(JTable table) is Row Header Visible Container p = table.getParent(); if (p instanceof JViewport) { Container gp = p.getParent(); if (gp instanceof JScrollPane) { JScrollPane scrollPane = (JScrollPane) gp; JViewport rowHeaderViewPort = scrollPane.getRowHeader(); if (rowHeaderViewPort != null) return rowHeaderViewPort.getView() != null; ... |
void | layoutHeaders(JTable p_Table) layout Headers int column = 0; for (java.util.Enumeration columns = p_Table.getTableHeader().getColumnModel().getColumns(); columns .hasMoreElements(); column++) { TableColumn c = (TableColumn) columns.nextElement(); Component component = c.getHeaderRenderer().getTableCellRendererComponent(p_Table, c.getHeaderValue(), false, false, -1, column); c.setPreferredWidth(Math.max(c.getPreferredWidth(), component.getPreferredSize().width)); |
void | makeHeaderFillEmptySpace(JTable table) Installs a custom Border on the given table's JTableHeader that paints any blank area to the right of the last column header with the JTableHeader 's background. table.getTableHeader().setBorder(createTableHeaderEmptyColumnPainter(table)); |
void | makeTableHeadersCentered(final JTable table, final boolean dataColsAlso) Sets a JTable to have the headers be centered. ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.CENTER); if (dataColsAlso) { TableCellRenderer tcr = table.getDefaultRenderer(String.class); DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) tcr; dtcr.setHorizontalAlignment(SwingConstants.CENTER); |
void | modifyTableHeader(JTableHeader head, Vector columnNames) Setzt den Header einer JTable TableColumnModel m = head.getColumnModel(); if (m.getColumnCount() != columnNames.size()) { System.out.println("Column mismatch: " + m.getColumnCount() + "/" + columnNames.size()); return; for (int i = 0; i < columnNames.size(); i++) { TableColumn c = m.getColumn(i); c.sizeWidthToFit(); ... |
void | paintHeader(Graphics graphics, JTable table, int x, int width) Paints the given JTable's table default header background at given x for the given 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);
|