Skip to content

Commit

Permalink
Merge pull request #5642 from firefly2442/finance-table-sortable
Browse files Browse the repository at this point in the history
feat: add sortable columns in the finance tab, addresses issue #4876
  • Loading branch information
HammerGS authored Jan 5, 2025
2 parents 1ac3262 + d8a6d2f commit d33a0aa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions MekHQ/src/mekhq/gui/FinancesTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import mekhq.gui.enums.MHQTabType;
import mekhq.gui.model.FinanceTableModel;
import mekhq.gui.model.LoanTableModel;
import mekhq.gui.sorter.*;
import mekhq.gui.utilities.JScrollPaneWithSpeed;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
Expand All @@ -54,6 +55,9 @@

import javax.swing.*;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

import java.awt.*;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
Expand Down Expand Up @@ -102,6 +106,12 @@ public void initTab() {

financeModel = new FinanceTableModel();
financeTable = new JTable(financeModel);
// make column headers in the table clickable and sortable
TableRowSorter<TableModel> sorter = new TableRowSorter<>(financeTable.getModel());
sorter.setComparator(FinanceTableModel.COL_DEBIT, new FormattedNumberSorter());
sorter.setComparator(FinanceTableModel.COL_CREDIT, new FormattedNumberSorter());
sorter.setComparator(FinanceTableModel.COL_BALANCE, new FormattedNumberSorter());
financeTable.setRowSorter(sorter);
financeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
FinanceTableMouseAdapter.connect(getCampaignGui(), financeTable, financeModel);
financeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
Expand Down

0 comments on commit d33a0aa

Please sign in to comment.