You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Giguère, Philippe <Ph...@finances.gouv.qc.ca> on 2010/07/07 17:15:08 UTC

Sort a column in a TableView with only image in the column cell.

Hi,

I have a TableView which allow to sort data. Everything works well except when the data are images. I can't sort the images like I want and the sort result isn't the same at each execution of the program.

Example of results:
First execution = Image1, Image1, Image2, Image2, Image3.
Second execution = Image3, Image1, Image1, Image2, Image2.

I searched why the result weren't never the same and I found that the TableViewRowComparator use the Comparable.compareTo(Object) method if the object implement Compare. If not, it use the toString() method that use the hash code of the object to sort. So, the hash code change for the object at each execution and it change the sort order as well at each execution.

I was wondering if there are a way already implented in Pivot to sort images or if you have some clue to do it? If not that could be an nice thing to add in the next version of Pivot.

Thx a lot

Philippe Giguère


------------------------------------------------------------------------
Avis de confidentialité: Ce courriel et les pièces qui y sont
jointes peuvent contenir des renseignements confidentiels qui ne
vous sont pas destinés. Si vous avez reçu cette correspondance par
erreur, veuillez la détruire et nous en aviser. Merci!

Devez-vous vraiment imprimer ce courriel ? Pensons à
l'environnement ...

Re: Sort a column in a TableView with only image in the column cell.

Posted by Greg Brown <gk...@mac.com>.
Another approach is to actually store sortable data in the column (such as an image file name or some sort of status value) but use a custom renderer to present that data as an image.
G

On Jul 7, 2010, at 11:39 AM, Noel Grandin wrote:

> Hi
> 
> You're going to need to implement your own Comparator, and set it on the list used by the TableView.
> 
> Or you could use something like the attached class, which allows you to set your own comparator for a column.
> 
> -- Noel Grandin
> 
> Giguère, Philippe wrote:
>> 
>> Hi,
>>  
>> I have a TableView which allow to sort data. Everything works well except when the data are images. I can't sort the images like I want and the sort result isn't the same at each execution of the program.
>>  
>> Example of results:
>> First execution = Image1, Image1, Image2, Image2, Image3.
>> Second execution = Image3, Image1, Image1, Image2, Image2.
>>  
>> I searched why the result weren't never the same and I found that the TableViewRowComparator use the Comparable.compareTo(Object) method if the object implement Compare. If not, it use the toString() method that use the hash code of the object to sort. So, the hash code change for the object at each execution and it change the sort order as well at each execution.
>>  
>> I was wondering if there are a way already implented in Pivot to sort images or if you have some clue to do it? If not that could be an nice thing to add in the next version of Pivot.
>>  
>> Thx a lot
>>  
>> Philippe Giguère
>> Avis de confidentialité: Ce courriel et les pièces qui y sont jointes peuvent contenir des renseignements confidentiels qui ne vous sont pas destinés. Si vous avez reçu cette correspondance par erreur, veuillez la détruire et nous en aviser. Merci!
>> 
>> Devez-vous vraiment imprimer ce courriel ? Pensons à l'environnement ...
> 
> <TableViewRowComparator2.java>


Re: Sort a column in a TableView with only image in the column cell.

Posted by Noel Grandin <no...@gmail.com>.
 Hi

You're going to need to implement your own Comparator, and set it on the list used by the TableView.

Or you could use something like the attached class, which allows you to set your own comparator for a column.

-- Noel Grandin

Giguère, Philippe wrote:
>
> Hi,
>
>  
>
> I have a TableView which allow to sort data. Everything works well except when the data are images. I can't sort the
> images like I want and the sort result isn't the same at each execution of the program.
>
>  
>
> Example of results:
>
> First execution = Image1, Image1, Image2, Image2, Image3.
>
> Second execution = Image3, Image1, Image1, Image2, Image2.
>
>  
>
> I searched why the result weren't never the same and I found that the TableViewRowComparator use the
> Comparable.compareTo(Object) method if the object implement Compare. If not, it use the toString() method that use the
> hash code of the object to sort. So, the hash code change for the object at each execution and it change the sort
> order as well at each execution.
>
>  
>
> I was wondering if there are a way already implented in Pivot to sort images or if you have some clue to do it? If not
> that could be an nice thing to add in the next version of Pivot.
>
>  
>
> Thx a lot
>
>  
>
> Philippe Giguère
>
> ------------------------------------------------------------------------------------------------------------------------
> *Avis de confidentialité:* Ce courriel et les pièces qui y sont jointes peuvent contenir des renseignements
> confidentiels qui ne vous sont pas destinés. Si vous avez reçu cette correspondance par erreur, veuillez la détruire
> et nous en aviser. Merci!
>
> Devez-vous vraiment imprimer ce courriel ? Pensons à l'environnement ...