我有这个模型表,我想从中删除选定的行。
public class ModelTabel extends AbstractTableModel {
private Table tSel;
private Archivio archivio;
public ModelTabel (Table tSel) {
this.tSel = tSel;
}
public int getRowCount() {
return tSel.getOrdine().getNumeroCibi();
}
public int getColumnCount() {
return 5;
}
public Object getValueAt(int rowIndex, int columnIndex) {
if(columnIndex == 0) {
return this.tSel.getOrdine().getCibo(rowIndex).getNome();
} else if(columnIndex == 1) {
if(this.tSel.getOrdine().getCibo(rowIndex).getQuantita() == 0) {
return "0";
} else {
return this.tSel.getOrdine().getCibo(rowIndex).getQuantita();
}
} else if(columnIndex == 2) {
return "€ " + this.tSel.getOrdine().getCibo(rowIndex).getPrezzo();
} else if(columnIndex == 3) {
if(this.tSel.getOrdine().getCibo(rowIndex).getQuantita() > 1) {
return true;
} else {
return false;
}
} else if(columnIndex == 4) {
return this.tSel.getOrdine().getCibo(rowIndex).getCuoco().getNome() + " " + this.tSel.getOrdine().getCibo(rowIndex).getCuoco().getCognome();
}
return null;
}
public String getColumnName(int column){
if(column == 0) {
return "Name";
} else if(column == 1) {
return "Q.ta";
} else if(column == 2) {
return "Price U.";
} else if(column == 3) {
return "Wait";
} else if(column == 4) {
return "Chef";
}
return null;
}
public Class getColumnClass(int i) {
if(i == 3) {
return Boolean.class;
}
return (Class) super.getColumnClass(i);
}
}
jButton怎么可能删除选定的行???我需要此代码中的选定行,然后????
public class ActionRemoveRow extends AbstractAction {
private Control control;
public ActionRemoveRow (Controllo controllo) {
this.control = control;
this.putValue(Action.NAME, "Remove");
this.putValue(Action.SHORT_DESCRIPTION, "Remove");
this.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R));
this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("CTRL R"));
}
public void actionPerformed(ActionEvent e) {
Vist vist = (Vist) this.control.getVist();
Panel p = (Panel) vist.getUndetVist(Constant.PANEL);
int rowSelected = p.getRowSelected();
}
}