Example usage for javax.swing.table TableStringConverter TableStringConverter

List of usage examples for javax.swing.table TableStringConverter TableStringConverter

Introduction

In this page you can find the example usage for javax.swing.table TableStringConverter TableStringConverter.

Prototype

TableStringConverter

Source Link

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();//from w ww  .ja  v a2s. c o m

    // 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);
            }
        }
    });
}