简体   繁体   English

JTable:存储与显示不同的数据

[英]JTable: Store different data than displaying

i have a question about the JTable in Java. 我对Java中的JTable有疑问。 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. 我知道在Flex中,像单元格的数据和标签之类的东西。

Is there anything similar in Java? Java中有类似的东西吗?

Thank you very much!! 非常感谢你!!

You can use a custom cell renderer to change how the value is displayed while keeping it in store with a sortable format: 您可以使用自定义单元格渲染器更改值的显示方式,同时以可排序的格式将其保存在存储区中:

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. 因此,数据应作为Date对象存储在模型中。 Then you use a renderer to format the date anyway you wish. 然后,您可以使用渲染器来格式化所需的日期。

Table Format Renderers shows you an easy way to do the formatting. 表格格式渲染器为您展示了一种简单的格式化方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM