私はカスタムtableModelを持つJTableを持っています。JTable "IndexOutOfBoundsException"から行を削除
List<Articoli> v = modelManager.getArticoliManager().estraiArticoli(false, true,false,true,true,null,false,null);
tableModel2 = new MyTableModelArticoliDett(listaMagazzino);
sorter = new TableRowSorter<MyTableModelArticoliDett>(tableModel2);
tableModel2.stampaTabella(v);
table = new CustomTableArticoliDett(tableModel2);
table.setRowSorter(sorter);
私が見ることができます:これは私のTableModelの構造
のDefaultTableModel
public class defaultTableModel extends DefaultTableModel{
public defaultTableModel(){}
public defaultTableModel(String[] ColName,int n){
super(ColName, n);
}
public void setValueAt(Object value,int row,int column){
super.setValueAt(value, row, column);
}
public void removeAllRow(){
//setRowCount(0);
System.out.println(getRowCount());
while(getRowCount() > 0)
{
removeRow(0);
}
}
}
MyTableModelArticoliDett
public class MyTableModelArticoliDett extends defaultTableModel{
public List<Articoli> v;
public LinkedHashMap<String,Articoli> mappaArticoli = new LinkedHashMap<String,Articoli>();
public List<Magazzino> listaMagazzino;
public MyTableModelArticoliDett(String[] ColName,List<Magazzino> listaMagazzino) {
super(ColName, 0); // 10 righe iniziali (vuote)
this.listaMagazzino = listaMagazzino;
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
public Class<Float> getColumnClass(Float columnIndex) {
return Float.class; // Le due colonne sono numeri interi
}
@SuppressWarnings("rawtypes")
public void stampaTabella(List<Articoli> v){
removeAllRow();
this.setV(v); // inizializzato con il vettore
int i=0;
for(Iterator<Articoli> it = v.iterator(); it.hasNext();){
Articoli articoli = it.next();
int numberCol=0;
mappaArticoli.put(articoli.getCodArticoloString(), articoli);
this.addRow(new Vector());
}
}
}
今、私は私のテーブル内の項目を挿入するには、このコードを使用していますアイテム。今、その後私は、レコードのサブセット(ESフィルター)を抽出するために、別のクエリを取得したい、この表を移入していたので、私は別のクエリを実行し、私はこのような「stampatabella」メソッドを呼び出します。
tableModel2.stampaTabella(new array);
しかし、私はこのエラーを持っている:
DEBUG [AWT-EventQueue-0] (MyLog4J.java:45) - java.lang.IndexOutOfBoundsException: Invalid range
at javax.swing.DefaultRowSorter.rowsDeleted(DefaultRowSorter.java:880)
at javax.swing.JTable.notifySorter(JTable.java:4274)
at javax.swing.JTable.sortedTableChanged(JTable.java:4118)
at javax.swing.JTable.tableChanged(JTable.java:4395)
at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:296)
at javax.swing.table.AbstractTableModel.fireTableRowsDeleted(AbstractTableModel.java:261)
at javax.swing.table.DefaultTableModel.removeRow(DefaultTableModel.java:464)
at com.mcsolution.table.MioTableModel.defaultTableModel.removeAllRow(defaultTableModel.java:38)
at com.mcsolution.table.MioTableModel.Annaelle.MyTableModelArticoliDett_Annaelle.stampaTabella(MyTableModelArticoliDett_Annaelle.java:30)
at com.mcsolution.easyMgmt.panel.articoli.articoliDettAbbigliamento.panelArticoliDett_GraficaAbbigliamento.filtraArticoliPerCategoria(panelArticoliDett_GraficaAbbigliamento.java:1320)
at com.mcsolution.easyMgmt.panel.articoli.articoliDettAbbigliamento.panelArticoliDett_GraficaAbbigliamento$2.actionPerformed(panelArticoliDett_GraficaAbbigliamento.java:822)
at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1260)
at javax.swing.JComboBox.setSelectedItem(JComboBox.java:588)
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:624)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:835)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:499)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
エラーは私の問題を修正することができますどのようにこの方法
public void removeAllRow(){
//setRowCount(0);
System.out.println(getRowCount());
while(getRowCount() > 0)
{
removeRow(0); //ROW WITH ERROR
}
}
にありますか?
EDIT
私はラインコードコメントをしようとした場合:
table.setRowSorter(sorter);
をコードが
すぐに役立つように、[MCVE]または[短く、自己完結型の正しい例](http://www.sscce.org/)を投稿してください。 –