sortabletablemodel.java

来自「Java中Swing界面库中几个类使用的例子」· Java 代码 · 共 58 行

JAVA
58
字号
/* (swing1.1) */package jp.gr.java_conf.tame.swing.table;import java.awt.*;import javax.swing.*;import javax.swing.table.*;/** * @version 1.0 02/25/99 */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 + =
减小字号Ctrl + -
显示快捷键?