-1
Personal I am a few years with a difficulty that even today I could not solve completely. By adding a TableRowSorter
to a JTable
automatically the columns can be ordered by clicking and with that I have a problem in picking the correct index, yes I tried to use the ConvertIndexToView
and ConvertIndexToModel
, I have looked in several places to disable the autosorter option when clicking the columns but without success.
Here it works perfectly I selected the index 1 and the record came correct according to the selected number
Second Image with the error, already in this I selected index 1 and with the filter active as shown pulls me the same record as in the previous image other than the view
After talking with Articuno I discovered the error in my code I checked the oracle example that worked perfectly and checked the line of the code where I obtained the objects of the model mine was like this:
@Override
public generics getObjeto(int rowIndex) {
//Se a quantidade de linhas do modelo não fosse igual da tabela
if (tabela.getModel().getRowCount() != tabela.getRowCount()) {
//Converta a linha para a index do modelo
return linhas.get(tabela.convertRowIndexToModel(rowIndex));
} else {
//Se não sao diferentes jogue a index para o modelo sem converter
return linhas.get(rowIndex);
}
}
After analyzing the example I removed the code unnecessarily getting as follows:
@Override
public generics getObjeto(int rowIndex) {
return linhas.get(tabela.convertRowIndexToModel(rowIndex));
}
Thanks to Articuno for the great patience, I promise to improve the posts.
Add a [mcve] of your code so it is possible to test the problem.
– user28595
I will play my problem and try to show in image
– Denis Benjamim
See this: https://pt.meta.stackoverflow.com/a/5485/28595
– user28595
Yes! I usually post the whole code but in this case it involves many classes, the model that I use in jtable is customized and also do not use the jtable itself I adapted using the Decoretor patter so I posted this way only so that it is understood my mistake. But I somehow decided to lock the column and I’m seeing what you sent me from the demo of the oracle itself I’ll see if I did something wrong during the procedure
– Denis Benjamim