Footer-Zeile in einer JTable

Was ist der beste Weg, um ein footer-Zeile in einer JTable? Hat jemand einen Beispielcode dazu?

Der einzige Ansatz, den ich gedacht habe, der so weit ist, um eine spezielle Zeile in die Tabelle ein Modell, das immer sortiert auf den Boden.


Hier ist, was ich am Ende mit:

JTable mainTable = new JTable(mainTableModel);
JTable footerTable = new JTable(footerModel);
footerTable.setColumnModel(mainTable.getColumnModel());

//Disable selection in the footer. Otherwise you can select the footer row
//along with a row in the table and that can look quite strange.
footerTable.setRowSelectionAllowed(false);
footerTable.setColumnSelectionAllowed(false);

JPanel tablePanel = new JPanel();
BoxLayout boxLayout = new BoxLayout(tablePanel, BoxLayout.Y_AXIS);
tablePanel.setLayout(boxLayout);
tablePanel.add(mainTable.getTableHeader()); //This seems like a bit of a WTF
tablePanel.add(mainTable);
tablePanel.add(footerTable);

Sortierung funktioniert gut, aber die Auswahl der Fußzeile ist ein bisschen seltsam.

InformationsquelleAutor Luke Quinane | 2009-06-11

Schreibe einen Kommentar