Example usage for javax.swing RowSorter getSortKeys

List of usage examples for javax.swing RowSorter getSortKeys

Introduction

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

Prototype

public abstract List<? extends SortKey> getSortKeys();

Source Link

Document

Returns the current sort keys.

Usage

From source file:org.rivalry.swingui.SortTablePanel.java

/**
 * @param tableModel Table model.//from   ww  w. ja v a  2  s  .com
 *
 * @return a new table.
 */
private JTable createTable(final TableModel tableModel) {
    final JTable answer = new ColumnNameToolTipTable(tableModel);

    answer.setAutoCreateRowSorter(true);
    answer.setGridColor(Color.GRAY);

    final RowSorter<? extends TableModel> rowSorter = answer.getRowSorter();
    rowSorter.addRowSorterListener(new RowSorterListener() {
        @Override
        public void sorterChanged(final RowSorterEvent event) {
            final List<? extends SortKey> sortKeys = rowSorter.getSortKeys();

            if (CollectionUtils.isNotEmpty(sortKeys)) {
                _userPreferences.putSortKey(sortKeys.get(0));
            }
        }
    });

    return answer;
}

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();//from w  w  w .j a  v  a2 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);
            }
        }
    });
}

From source file:pcgen.gui2.tabs.EquipInfoTab.java

public EquipInfoTab() {
    super("Equip");
    //TODO: remove this when optimized sorting is implemented
    this.equipmentTable = new JDynamicTable() {

        @Override/* ww w.ja v  a  2  s. c  om*/
        public void setModel(TableModel dataModel) {
            RowSorter<? extends TableModel> oldRowSorter = getRowSorter();
            super.setModel(dataModel);
            RowSorter<? extends TableModel> newRowSorter = getRowSorter();
            if (newRowSorter != null && oldRowSorter != null) {
                newRowSorter.setSortKeys(oldRowSorter.getSortKeys());
            }
        }

    };
    this.equipViewBox = new JComboBox<>(EquipView.values());
    this.infoPane = new InfoPane();
    this.equipmentSetTable = new JTreeTable() {

        @Override
        protected void configureEnclosingScrollPane() {
            //We do nothing so the table is displayed without a header
        }

    };
    this.equipButton = new JButton();
    this.unequipButton = new JButton();
    this.unequipAllButton = new JButton();
    this.moveUpButton = new JButton();
    this.moveDownButton = new JButton();
    this.equipSetBox = new JComboBox<>();
    this.newSetButton = new JButton();
    this.removeSetButton = new JButton();
    this.exportTemplateButton = new JButton();
    this.viewBrowserButton = new JButton();
    this.exportFileButton = new JButton();
    this.setNoteButton = new JButton();
    this.expandAllButton = new JButton();
    this.collapseAllButton = new JButton();
    this.weightLabel = new JLabel();
    this.loadLabel = new JLabel();
    this.limitLabel = new JLabel();
    initComponents();
}