我有一个使用我创建的自定义 TableModel 填充的 JTable。我有另一个 JTable,可以从第一个 JTable 添加行。我可以将该行添加到新的 JTable 没有问题,但我需要在将其添加到新的 JTable 时从第一个 JTable 中删除该行。不幸的是 removeRow() 只是 DefaultTableModel 的一种方法,我已经检查了源代码,但它没有显示出来......
提前致谢!
这是我的自定义表格模型:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ttp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.*;
import java.util.*;
/**
*
* @author ericrea
*/
/**creates the model for the accounts table*/
public class tableModel extends AbstractTableModel {
//private int rowCount = 0;
private static final int COLUMN_COUNT = 3;
private Conceptual_Package pp;
Conceptual_Package j = GUIpos.i;
public tableModel(Conceptual_Package pp) {
this.pp = pp;
}
/**sets the column headers*/
public String getColumnName(int i){
switch (i) {
case 0:
return "Sec";
case 1:
return "Row";
case 2:
return "Seat";
default:
return null;
}
}
/**figures out how many rows the model needs*/
public int getRowCount() {
int h = 0;
try {
h = Physical_PackageDAO.getInstance().getByConceptual_Package(j.getId()).size();
} catch (DataException ex) {
Logger.getLogger(tableModel.class.getName()).log(Level.SEVERE, null, ex);
}
return h;
}
/**Figures out number of columns*/
public int getColumnCount() {
return COLUMN_COUNT;
}
/**gets the account information from the Physical_Package*/
public Object getValueAt(int rowIndex, int columnIndex) {
String a = null;
String b = null;
String c = null;
try {
Physical_Package pp = Physical_PackageDAO.getInstance().getByConceptual_Package(j.getId()).get(rowIndex);
a = pp.getVenueSeat().getRowInVenue().getSectionInVenue().getSectionNumber();
b = pp.getVenueSeat().getRowInVenue().getRowNumber();
c = pp.getVenueSeat().getSeatNumber();
} catch (DataException ex) {
Logger.getLogger(tableModel.class.getName()).log(Level.SEVERE, null, ex);
}
switch (columnIndex) {
case 0:
return a.trim();
case 1:
return b.trim();
case 2:
return c.trim();
default:
return null;
}
}
/**gets the right account for the Physical_Package*/
public Physical_Package getCPackage(int index){
Physical_Package d = null;
try {
Physical_PackageDAO.getInstance().getByConceptual_Package(j.getId()).get(index);
} catch (DataException ex) {
Logger.getLogger(tableModel.class.getName()).log(Level.SEVERE, null, ex);
}
return d;
}
public void removeRow(int index){
}
//write in mainFrame, in panel
//ValueChanged{
// get the selected name
// Physical_Packages.get()
// namefield.settext(pp.getname);
//
//}
}