Reputation: 11
i have a question about the JTable in Java. Im reading Time-String from a database in the international standard-format (year:month:day Hours:Minutes). Thats cool beacause of sorting my table by time.
BUT the client wants to display the time in the format day:month:year Hours:Minutes). Its no problem to display it this way, but easy sorting is not possible anymore.
Im searching for a solution to store the original data for sorting and display the new format. I know in Flex there is such a thing like data und label for a cell.
Is there anything similar in Java?
Thank you very much!!
Upvotes: 1
Views: 548
Reputation: 324128
Generally date information should not be stored as a String for the reason you just gave. Different application want to format the data differently. So the data should be stored as a Date object in the model. Then you use a renderer to format the date anyway you wish.
Table Format Renderers shows you an easy way to do the formatting.
Upvotes: 0
Reputation: 9862
You can use a custom cell renderer to change how the value is displayed while keeping it in store with a sortable format:
Upvotes: 1