Skip to main content

【getRowCount issue of JXTable in SwingX 1.0.jar】

7 replies [Last post]
nepxion
Offline
Joined: 2010-04-19
Points: 0

I do an addTableModelListener to the model of JXTable as follows:

public void tableChanged(TableModelEvent e) {

....

int rowCount = table.getRowCount();
System.out.println(rowCount);

....

}

Then I add some rows to table, it will fire a TableModelEvent, rowCount will be printed. The issue is sometime that it will be printed as the old rowCount. I just test it for 20 times and about 3 times it will be printed error count. This situation will not ALWAYS happen everytime. Would you confirm it is a bug?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

What happens when you test with the latest release?

Karl

nepxion
Offline
Joined: 2010-04-19
Points: 0

Sorry, my code can't compile through with the latest release, so it only works under the SwingX 1.0.

I guess the issus is caused by thread-safety, I just add/delete 2 same rows by clicking a button repleatly, sometime JXTable.getRowCount will show me the old row count.I think when I get row count, a thread now calculate the row count, so if I do this when calculating is finished, the count is correct, otherwise error. If I do Thread.sleep(2000), then begin to get row count, will it be ok?

If I change to table.getModel().getRowCount() instead of table.getRowCount, it always be correct.

for (int i=0; i < table.getModel().getRowCount(); i++)

{

table.convertRowIndexToModel(i);

}

Sometime table.getModel().getRowCount() > table.getRowCount, the above code will cause OutOfIndex exception.

BTW:

I find that in your trunk, the code in JXTable is:
public int getRowCount() {

return table.getModel().getRowCount();

}

And in 1.0, the code in JXTable is:

public int getRowCount()

{

return filters != null ? filters.getOutputSize() : super.getRowCount();

}

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Sounds like you may not be correctly notifying the view of model changes.  Can you replicate this behavior with a standard JTable?

Karl

nepxion
Offline
Joined: 2010-04-19
Points: 0

The view is displayed correctly.
For example:
At first there are 4 rows on JXTable and I add 2 rows to it.
I can see 6 rows on table, but the row count I print is 4.
Then I delete the adding 2 rows and add them again, the row count is 6, correctly.
Notice I can't reproduce this EVERYTIME.

kschaefe
Offline
Joined: 2006-06-08
Points: 0

You didn't answer the question: can you replicate the buggy behavior with JTable?

Karl

nepxion
Offline
Joined: 2010-04-19
Points: 0

It is ok in JTable

kschaefe
Offline
Joined: 2006-06-08
Points: 0

Please supply a small, runnable demo showcasing the issue.  I need a working test case.

Karl