📄 myclienttable.java
字号:
/* * MyClientTable.java * * Created on 2003年5月8日, 下午8:36 *//** * * @author administrator */import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.*;import javax.swing.event.*;import java.util.*;class DataModel extends AbstractTableModel { Object[][] data = { {"书名", "作者", "编号", "价格"}, {"one", "two", "three", "four"}, {"five", "six", "seven", "eight"}, {"nine", "ten", "eleven", "twelve"}, }; Vector vData=null; /** Creates a new instance of MyClientTable */ public DataModel() { } public DataModel(Vector v) { if(v!=null) vData=v; } /** Returns the number of columns in the model. A * <code>JTable</code> uses this method to determine how many columns it * should create and display by default. * * @return the number of columns in the model * @see #getRowCount * */ public int getColumnCount() { if(vData==null) return data[0].length; else return ((Vector)(vData.elementAt(0))).size(); } /** Returns the number of rows in the model. A * <code>JTable</code> uses this method to determine how many rows it * should display. This method should be quick, as it * is called frequently during rendering. * * @return the number of rows in the model * @see #getColumnCount * */ public int getRowCount() { if(vData==null) return (data.length-1); else return (vData.size()-1); } /** Returns the value for the cell at <code>columnIndex</code> and * <code>rowIndex</code>. * * @param rowIndex the row whose value is to be queried * @param columnIndex the column whose value is to be queried * @return the value Object at the specified cell * */ public Object getValueAt(int rowIndex, int columnIndex) { if(vData==null) return data[rowIndex+1][columnIndex]; else return ((Vector)(vData.elementAt(rowIndex+1))).elementAt(columnIndex); } public String getColumnName(int column) { if(vData==null) return data[0][column].toString(); else return ((Vector)(vData.elementAt(0))).elementAt(column).toString(); }}class MyClientTable extends JTable { /** Creates a new instance of MyClientTable */ public MyClientTable() { super(new DataModel()); } public MyClientTable(Vector v) { super(new DataModel(v)); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -