JTable: setRowSorter(RowSorter arg0) : JTable « javax.swing « Java by API






JTable: setRowSorter(RowSorter arg0)

  

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

public class Main extends JFrame {
  public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    String[] columns = { "Item", "Price" };

    Object[][] rows = { { "Potatoes", 10.98 }, { "Magazine", 7.99 },
        { "Can of soup", 0.89 }, { "DVD movie", 39.99 } };

    TableModel model = new DefaultTableModel(rows, columns) {
      public Class getColumnClass(int column) {
        if (column >= 0 && column <= getColumnCount())
          return getValueAt(0, column).getClass();
        else
          return Object.class;
      }
    };
    JTable table = new JTable(model);
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);
    getContentPane().add(new JScrollPane(table));

    setSize(200, 150);
    setVisible(true);
  }

  public static void main(String[] args) {
    new Main();
  }
}

   
    
  








Related examples in the same category

1.TableHeader.cellBorder
2.Table.scrollPaneBorder
3.JTable.AUTO_RESIZE_ALL_COLUMNS
4.JTable.AUTO_RESIZE_LAST_COLUMN
5.JTable.AUTO_RESIZE_NEXT_COLUMN
6.JTable.AUTO_RESIZE_OFF
7.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
8.new JTable(Object name, Object[][] data)
9.new JTable(TableModel dm)
10.new JTable(Vector rowData, Vector columnNames)
11.JTable: addColumnSelectionInterval(int index0, int index1)
12.JTable: changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
13.JTable: clearSelection()
14.JTable: configureEnclosingScrollPane() 'Headerless Table'
15.JTable: createDefaultColumnsFromModel()
16.JTable: getCellSelectionEnabled()
17.JTable: getColumnCount()
18.JTable: getColumnModel()
19.JTable: getColumnSelectionAllowed()
20.JTable: getIntercellSpacing()
21.JTable: getRowCount()
22.JTable: getRowSelectionAllowed()
23.JTable: getSelectedColumns()
24.JTable: getSelectedRows()
25.JTable: getSelectionModel()
26.JTable: getTableHeader()
27.JTable: getValueAt(int row, int column)
28.JTable: isCellSelected(int row, int column)
29.JTable: moveColumn(int column, int targetColumn)
30.JTable: print()
31.JTable: print(PrintMode p, MessageFormat hFormat, MessageFormat fFormat)
32.JTable: removeColumn(TableColumn aColumn)
33.JTable: removeColumnSelectionInterval(int index0, int index1)
34.JTable: removeRowSelectionInterval(int index0, int index1)
35.JTable: selectAll()
36.JTable: setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel)
37.JTable: setAutoResizeMode(int m)
38.JTable: setCellSelectionEnabled(boolean cellSelectionEnabled)
39.JTable: setColumnSelectionAllowed(boolean columnSelectionAllowed)
40.JTable: setDefaultEditor(Class columnClass, TableCellEditor editor)
41.JTable: setDefaultRenderer(Class columnClass, TableCellRenderer renderer)
42.JTable: setFocusable(boolean focusable)
43.JTable: setGridColor(Color gridColor)
44.JTable: setIntercellSpacing(Dimension intercellSpacing)
45.JTable: setPreferredScrollableViewportSize(Dimension size)
46.JTable: setRowHeight(int rowHeight)
47.JTable: setRowSelectionAllowed(boolean rowSelectionAllowed)
48.JTable: setRowSelectionInterval(int index0, int index1)
49.JTable: setSelectionMode(int m)
50.JTable: setShowGrid(boolean showGrid)
51.JTable: setShowHorizontalLines(boolean showHorizontalLines)
52.JTable: setTableHeader(JTableHeader tableHeader)
53.JTable: setShowVerticalLines(boolean showVerticalLines)
54.JTable: setValueAt(Object aValue, int row, int column)