Example usage for javax.swing RowSorter toggleSortOrder

List of usage examples for javax.swing RowSorter toggleSortOrder

Introduction

In this page you can find the example usage for javax.swing RowSorter toggleSortOrder.

Prototype

public abstract void toggleSortOrder(int column);

Source Link

Document

Reverses the sort order of the specified column.

Usage

From source file:org.yccheok.jstock.gui.portfolio.DividendSummaryJDialog.java

/** Creates new form DividendSummaryJDialog */
public DividendSummaryJDialog(java.awt.Frame parent, boolean modal, DividendSummary dividendSummary,
        PortfolioManagementJPanel portfolioManagementJPanel) {
    super(parent, modal);
    this.portfolioManagementJPanel = portfolioManagementJPanel;
    // Clone another copy to avoid original copy from being corrupted.
    this.dividendSummary = new DividendSummary(dividendSummary);
    this.dividendSummaryAfterPressingOK = null;
    initComponents();/*w w  w. j a  v a  2 s .c om*/

    // Hackish way to make Mac works.
    pack();
    setSize(new java.awt.Dimension(339, 373));
    setLocationRelativeTo(null);

    ((TableRowSorter) this.jTable1.getRowSorter()).setStringConverter(new TableStringConverter() {

        @Override
        public String toString(TableModel model, int row, int column) {
            if (model.getColumnClass(column) == StockInfo.class) {
                return ((StockInfo) model.getValueAt(row, column)).symbol.toString();
            }

            return model.getValueAt(row, column).toString();
        }
    });

    // Sort by date, with latest comes first.
    final RowSorter<? extends TableModel> rowSorter = this.jTable1.getRowSorter();
    if (rowSorter != null) {
        rowSorter.toggleSortOrder(0);
        final List<? extends SortKey> sortKeys = rowSorter.getSortKeys();
        if (sortKeys.size() > 0) {
            if (sortKeys.get(0).getSortOrder() != javax.swing.SortOrder.DESCENDING) {
                rowSorter.toggleSortOrder(0);
            }
        }
    }

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            AutoDividendTask autoDividendTask = DividendSummaryJDialog.this.autoDividendTask;
            if (autoDividendTask != null) {
                autoDividendTask.cancel(true);
            }
        }
    });
}