📄 sortabletablemodel.java
字号:
/* (swing1.1) */package tame.table;import javax.swing.table.DefaultTableModel;/**@version 1.0 02/25/99@author Nobuo Tamemasa*/public class SortableTableModel extends DefaultTableModel { int[] indexes; TableSorter sorter; public SortableTableModel() { } public Object getValueAt(int row, int col) { int rowIndex = row; if (indexes != null) { rowIndex = indexes[row]; } return super.getValueAt(rowIndex, col); } public void setValueAt(Object value, int row, int col) { int rowIndex = row; if (indexes != null) { rowIndex = indexes[row]; } super.setValueAt(value, rowIndex, col); } public void sortByColumn(int column, boolean isAscent) { if (sorter == null) { sorter = new TableSorter(this); } sorter.sort(column, isAscent); fireTableDataChanged(); } public int[] getIndexes() { int n = getRowCount(); if (indexes != null) { if (indexes.length == n) { return indexes; } } indexes = new int[n]; for (int i=0; i<n; i++) { indexes[i] = i; } return indexes; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -