?? mytablemodel.java
字號:
package connex.app.utils.TableUtils;
import javax.swing.table.AbstractTableModel;
import java.util.Vector;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class MyTableModel extends AbstractTableModel {
private boolean DEBUG = true;
private String[] columnNames = null;
public MyTableModel(String[] columnNames) {
this.columnNames = columnNames;
}
private Vector data = new Vector();
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.size();
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return ((TableRow) data.elementAt(row)).get(col);
}
public void addRow(TableRow ob) {
ob.setModel(this);
data.addElement(ob);
fireTableRowsInserted(0, data.size());
}
public void removeRow(int i) {
data.removeElementAt(i);
this.fireTableRowsDeleted(0, data.size());
}
public void removeRow(TableRow ob){
data.removeElement(ob);
this.fireTableRowsDeleted(0, data.size());
}
public void clear() {
data.removeAllElements();
this.fireTableRowsDeleted(0, data.size());
}
public TableRow getRow(int row) {
return (TableRow) data.elementAt(row);
}
public int getRowPosition(TableRow row) {
return data.indexOf(row);
}
public TableRow getRow(String id) {
TableRow tr = null;
for (int i = 0; i < this.getRowCount(); i++) {
if (id.equals(((TableRow) data.elementAt(i)).getID())) {
tr = (TableRow) data.elementAt(i);
break;
}
}
return tr;
}
/*
* JTable uses this method to determine the default renderer/
* editor for each cell. If we didn't implement this method,
* then the last column would contain text ("true"/"false"),
* rather than a check box.
*/
/* public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}*/
/*
* Don't need to implement this method unless your table's
* editable.
*/
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
if (col < 4) {
return false;
} else {
return true;
}
}
/*
* Don't need to implement this method unless your table's
* data can change.
*/
public void setValueAt(Object value, int row, int col) {
if (DEBUG) {
/* System.out.println("Setting value at " + row + "," + col
+ " to " + value
+ " (an instance of "
+ value.getClass() + ")");*/
}
if (data.size() <= row) {
data.addElement(new TableRow());
fireTableRowsInserted(0, data.size());
}
if (((TableRow) data.elementAt(0)).get(col) instanceof Integer
&& !(value instanceof Integer)) {
try {
((TableRow) data.elementAt(row)).add(col, new Integer(value.
toString()));
fireTableCellUpdated(row, col);
} catch (NumberFormatException e) {
}
} else {
((TableRow) data.elementAt(row)).add(col, value);
fireTableCellUpdated(row, col);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -