本文整理汇总了Java中javax.swing.table.TableRowSorter.setSortKeys方法的典型用法代码示例。如果您正苦于以下问题:Java TableRowSorter.setSortKeys方法的具体用法?Java TableRowSorter.setSortKeys怎么用?Java TableRowSorter.setSortKeys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.table.TableRowSorter
的用法示例。
在下文中一共展示了TableRowSorter.setSortKeys方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateClusterTable
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
private void updateClusterTable() {
int index = annotationSetCombo.getSelectedIndex();
AnnotationSet annotationSet = annotationSetCombo.getItemAt(index).getValue();
ClusterTableModel clusterModel = new ClusterTableModel(annotationSet);
int widths[] = getColumnWidths(clusterTable);
clusterTable.setModel(clusterModel);
setColumnWidths(clusterTable, widths);
TableColumn collapsedColumn = clusterTable.getColumnModel().getColumn(ClusterTableModel.COLLAPSED_COLUMN_INDEX);
collapsedColumn.setCellRenderer(new ClusterTableCollapsedCellRenderer(iconManager));
// sort
TableRowSorter<TableModel> sorter = new TableRowSorter<>(clusterTable.getModel());
clusterTable.setRowSorter(sorter);
List<SortKey> sortKeys = new ArrayList<>(2);
sortKeys.add(new RowSorter.SortKey(ClusterTableModel.NODES_COLUMN_INDEX, SortOrder.DESCENDING));
sortKeys.add(new RowSorter.SortKey(ClusterTableModel.CLUSTER_COLUMN_INDEX, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
sorter.sort();
}
示例2: createSorter
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/** Get a table row sorter */
@Override
public RowSorter<ProxyTableModel<Controller>> createSorter() {
TableRowSorter<ProxyTableModel<Controller>> sorter =
new TableRowSorter<ProxyTableModel<Controller>>(this);
sorter.setSortsOnUpdates(true);
LinkedList<RowSorter.SortKey> keys =
new LinkedList<RowSorter.SortKey>();
keys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(keys);
if (isFiltered())
sorter.setRowFilter(createFilter());
return sorter;
}
示例3: setSorter
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
private void setSorter(TableModel model) {
TableRowSorter<TableModel> sorter = new TableRowSorter<>(model);
sorter.setSortsOnUpdates(true);
LinkedList<RowSorter.SortKey> sortKeys = new LinkedList<>();
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
sorter.sort();
setRowSorter(sorter);
}
示例4: LobbyGameTable
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
LobbyGameTable(final LobbyGameTableModel gameTableModel) {
super(gameTableModel);
final TableRowSorter<LobbyGameTableModel> tableSorter = new TableRowSorter<>(gameTableModel);
// by default, sort newest first
final int dateColumn = gameTableModel.getColumnIndex(LobbyGameTableModel.Column.Started);
tableSorter.setSortKeys(Collections.singletonList(new RowSorter.SortKey(dateColumn, SortOrder.DESCENDING)));
setRowSorter(tableSorter);
}
示例5: setRowSorter
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
public void setRowSorter(final int column, final Comparator<?> comparator) {
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(table.getModel());
sorter.setSortsOnUpdates(true);
sorter.setComparator(column, null);
setRowSorter(sorter);
sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(column, SortOrder.ASCENDING)));
}
示例6: setLayout4JTableComponents
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/**
* Sets the layout for the JTable of the NetworkComponents.
*/
private void setLayout4JTableComponents() {
// --- Set Sorter for the table -------------------
TableRowSorter<DefaultTableModel> tblSorter = new TableRowSorter<DefaultTableModel>(this.getDefaultTableModel4Components());
this.getJTableComponents().setRowSorter(tblSorter);
// --- Define a comparator for the first row ------
tblSorter.setComparator(0, new Comparator<String>() {
@Override
public int compare(String netCompId1, String netCompId2) {
Integer ncID1 = null;
Integer ncID2 = null;
try {
ncID1 = Integer.parseInt(netCompId1.replaceAll("\\D+",""));
ncID2 = Integer.parseInt(netCompId2.replaceAll("\\D+",""));
} catch (NumberFormatException nfe) {
}
if (ncID1!=null & ncID2!=null) {
return ncID1.compareTo(ncID2);
}
return netCompId1.compareTo(netCompId2);
}
});
// --- Define the first sort order ----------------
List<SortKey> sortKeys = new ArrayList<SortKey>();
for (int i = 0; i < this.getJTableComponents().getColumnCount(); i++) {
sortKeys.add(new SortKey(i, SortOrder.ASCENDING));
}
tblSorter.setSortKeys(sortKeys);
tblSorter.sort();
// --- Define the column widths -------------------
TableColumnModel colModel = this.getJTableComponents().getColumnModel();
colModel.getColumn(0).setPreferredWidth(40);
colModel.getColumn(0).setCellRenderer(new BasicGraphGuiTableCellRenderEditor());
colModel.getColumn(0).setCellEditor(new BasicGraphGuiTableCellRenderEditor());
colModel.getColumn(1).setPreferredWidth(40);
colModel.getColumn(1).setCellRenderer(new BasicGraphGuiTableCellRenderEditor());
colModel.getColumn(2).setPreferredWidth(30);
colModel.getColumn(2).setCellRenderer(new TableCellRenderer4Button());
colModel.getColumn(2).setCellEditor(new TableCellEditor4TableButton(getGraphController(), jTableComponents));
}
示例7: test
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
static void test(final List<RowSorter.SortKey> sortKeys) {
final JFrame frame = new JFrame();
try {
frame.setUndecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
table = new JTable();
DefaultTableModel tableModel =
new DefaultTableModel(10, 1) {
public Object getValueAt(int row, int column) {
return row == getRowCount() - 1 ? row + "==last" :
row;
}
};
table.setModel(tableModel);
TableRowSorter<TableModel> sorter =
new TableRowSorter<TableModel>(tableModel);
sorter.setSortKeys(sortKeys);
table.setRowSorter(sorter);
frame.setContentPane(table);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
int lastRow = table.getRowCount() - 1;
//select last row
table.setRowSelectionInterval(lastRow, lastRow);
//remove row above the last
tableModel.removeRow(lastRow - 1);
lastRow = table.getRowCount() - 1;
if (lastRow != table.getSelectedRow()) {
throw new RuntimeException("last row must be still selected");
}
//sort table
sortKeys.clear();
sortKeys.add(0, new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
//remove row above the last
lastRow = table.getRowCount() - 1;
tableModel.removeRow(lastRow - 1);
if (!table.getValueAt(table.getSelectedRow(), 0).toString()
.endsWith("==last")) {
throw new RuntimeException(
"row ends with \"==last\" row must be still selected");
}
//make table unsorted again
sortKeys.clear();
sortKeys.add(0, new RowSorter.SortKey(0, SortOrder.UNSORTED));
sorter.setSortKeys(sortKeys);
//remove row above the last
lastRow = table.getRowCount() - 1;
tableModel.removeRow(lastRow - 1);
lastRow = table.getRowCount() - 1;
if (lastRow != table.getSelectedRow()) {
throw new RuntimeException(
"last row must be still selected");
}
} finally {
frame.dispose();
}
}
示例8: initialize
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame("Library Book Loan System - Notifications");
frame.setResizable(false);
frame.setBounds(100, 100, 438, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);
JLabel lblNotifications = new JLabel("Notifications");
lblNotifications.setHorizontalAlignment(SwingConstants.CENTER);
lblNotifications.setFont(new Font("Segoe UI Light", Font.PLAIN, 14));
lblNotifications.setBounds(10, 40, 414, 22);
panel.add(lblNotifications);
JLabel label_1 = new JLabel("Library Book Loan System");
label_1.setHorizontalAlignment(SwingConstants.CENTER);
label_1.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
label_1.setBounds(10, 11, 414, 25);
panel.add(label_1);
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Available Books", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
panel_1.setBounds(10, 73, 414, 177);
panel.add(panel_1);
panel_1.setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 22, 394, 144);
panel_1.add(scrollPane);
Object columnNames[] = { "No", "Message" };
Object rowData[][] = getNotifications();
table = new JTable(rowData, columnNames)
{
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
table.setBackground(Color.white);
table.setOpaque(true);
table.getTableHeader().setReorderingAllowed(false);
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(table.getModel());
table.setRowSorter(sorter);
List<RowSorter.SortKey> sortKeys = new ArrayList<>(25);
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
table.getColumnModel().getColumn(0).setMaxWidth(40);
scrollPane.setViewportView(table);
}
示例9: updateIssuesTable
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
private void updateIssuesTable() {
List<ScanTreeNode> selectedNodes = Lists.newArrayList((ScanTreeNode) issuesComponentsTree.getModel().getRoot());
if (issuesComponentsTree.getSelectionPaths() != null) {
selectedNodes.clear();
TreePath[] selectedTreeNodes = issuesComponentsTree.getSelectionPaths();
for (TreePath treePath : selectedTreeNodes) {
selectedNodes.add((ScanTreeNode) treePath.getLastPathComponent());
}
}
TableModel model = ScanManagerFactory.getScanManager(project).getFilteredScanIssues(selectedNodes);
TableRowSorter<TableModel> sorter = new TableRowSorter<>(model);
issuesTable.setRowSorter(sorter);
issuesTable.setModel(model);
List<RowSorter.SortKey> sortKeys = new ArrayList<>();
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
sorter.sort();
resizeTableColumns();
issuesTable.validate();
issuesTable.repaint();
}
示例10: sort
import javax.swing.table.TableRowSorter; //导入方法依赖的package包/类
/**
* Toggle-sort a column
* @param columnIndex The index of the column to be sorted
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private void sort(int columnIndex){
// Get the default, already registered, sorter
TableRowSorter sorter = (TableRowSorter)getTable().getRowSorter();
// Ensure the row is sortable
sorter.setSortable(columnIndex, true);
// Disable the row sorting capability to remove the native functionality
sorter.toggleSortOrder(columnIndex);
// Let all listeners (ui-display-related objects) know that we've sorted, so
// please repaint()
int rowCount = getTable().getRowCount();
getModel().fireTableRowsUpdated(0, rowCount - 1);
// If the column clicked doesn't match the last column that was sorted, there is
// no need to toggle, and we'll just sort descending
if (lastSorted != columnIndex){
descending = true;
lastSorted = columnIndex;
}
// If the direction is descending, sort descending
if (descending){
sorter.setSortKeys( Arrays.asList( new RowSorter.SortKey( columnIndex, SortOrder.DESCENDING ) ) );
}
// Otherwise, sort ascending
else {
sorter.setSortKeys( Arrays.asList( new RowSorter.SortKey( columnIndex, SortOrder.ASCENDING ) ) );
}
// Toggle the sort direction, in case we click on the chosen column again
descending = !descending;
}