I ran into the problem of duplicating lines in JXTable. If I sort the data JXTableand new rows are inserted in JXTable, the final result in JXTableshows duplicate rows that lead to an incorrect result in the table. Even it also shows the correct number of rows that were inserted, but some rows are completely missing, while some rows are found duplicated in JXTable.
If I sort JXTableafter all the data has been inserted successfully, then it shows the correct data, i.e. there are no duplicate rows and missing rows.
code example: I have a method to which I pass defaultTableModel, and now I add elements to the table
public void addingItems(DefaultTableModel defaultTableModel)
{
for(int i=0;i< numberofItems;i++){
Vector vobject = new Vector();
vobject.add("...");
vobject.add("xxx");
vobject.add("yyy");
...
..
vobject.add("");
defaultTableModel.addRow(vobject);
}
on the other hand I have add sort code to tableHeader actionlistener
tableheader.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
Vector data = defaultTableModel.getDataVector();
Collections.sort(data, new ColumnSorter(colIndex, ascending));
}
});
I put the code in a block synchronized, but did not succeed.
Please provide the best solution to solve this problem.
source
share