我使用Jpanel和Jlabel作为我的jtable中的render-component。如果没有足够的条目填充整个表格,我会添加“假条目”(= JLabel没有文字) 它有时会在删除后在jtable中显示文本。每个entrie包含最后一个表entrie的文本(在删除之前),例如“Gegeben Bar ......” 即使调用重画也无法解决问题。只有在插入新行后,才能正确显示表格。在linux上运行时jre是1.4_09
这是我在清理表格元素后所做的事情
model.fireTableRowsDeleted( firstRow, firstRow + rowCount - 1);
model.fireTableDataChanged();
我有一个函数来在出现问题时记录表元素和组件
for(int i=0; i < model.getRowCount();i++){
try
{
bw.newLine();
bw.write("el"+i+" "+model.getValueAt(i, 1)+"->" +model.getValueAt(i, 1).hashCode());
bw.newLine();
bw.write(" ->"+((JPanel)renderer.getTableCellRendererComponent(this, model.getValueAt(i,1),false, false, i, 0)).getComponent(0).hashCode()+"->" +((JPanel)renderer.getTableCellRendererComponent(this, model.getValueAt(i,1),false, false, i, 0)).getComponent(0));
bw.newLine();
if(observedElement.getElements().size()>i)
bw.write(" -> "+observedElement.getElements().get(i));
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
在输出中你可以看到元素和jlabel都没有包含文本
el0 ->5840819
->20546691->javax.swing.JLabel[,4,0,273x19,alignmentX=0.0,alignmentY=null,border=,flags=8,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEFT,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=<html><font face="Inconsolata,Inconsolata"></font></html>,verticalAlignment=CENTER,verticalTextPosition=CENTER]
->
el1 ->5840819
->20546691->javax.swing.JLabel[,4,0,273x19,alignmentX=0.0,alignmentY=null,border=,flags=8,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEFT,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=<html><font face="Inconsolata,Inconsolata"></font></html>,verticalAlignment=CENTER,verticalTextPosition=CENTER]
->
el2 ->5840819
->20546691->javax.swing.JLabel[,4,0,273x19,alignmentX=0.0,alignmentY=null,border=,flags=8,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEFT,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=<html><font face="Inconsolata,Inconsolata"></font></html>,verticalAlignment=CENTER,verticalTextPosition=CENTER]
->
...
任何想法可能是问题的原因或如何解决它?