JTable Multiple Header Rows

We had the same requirement in our last project. What I have found is an Implementation for a GroupableTableHeader on java2s.com. However, I have pimped it a bit, although I cannot recall what exactly. Beneath is the implementation of the three classes as how we use them. ColumnGroup.java import java.awt.Component; import java.awt.Dimension; import java.util.ArrayList; import … Read more

How to merge cell in DefaultTableModel/JTable?

MultiSpanCellTableExample demonstrates how to merge cells by creating a custom TableUI. There seem to be a problem in this example that causes StackOverflowError, at least in Java 6. To fix this, inside AttributiveCellTableModel.setDataVector() replace: setColumnIdentifiers(columnNames); with: this.columnIdentifiers = columnNames; IE: public void setDataVector(Vector newData, Vector columnNames) { if (newData == null) throw new IllegalArgumentException( “setDataVector() … Read more

JTable Right Align Header

Here’s an alternate approach to modifying the TableCellRenderer of a table’s JTableHeader. It’s not strictly necessary for this usage, but it minimizes the impact on the UI delegate’s appearance. Typical usage: JTable table = new JTable(…); JTableHeader header = table.getTableHeader(); header.setDefaultRenderer(new HeaderRenderer(table)); Custom header renderer: private static class HeaderRenderer implements TableCellRenderer { DefaultTableCellRenderer renderer; public … Read more

How can I put a control in the JTableHeader of a JTable?

There are two parts of the problem (as I see it 🙂 Usability: inventing UI-interaction/elements is prone to confusing users. In no particular order: the column header title is meant to describe the content of the column, that content description is lost when in replacing it with an action description it’s not immediately (for me, … Read more