TableModel 列区分数字类型
我有一个用于存储数字的 JTable。我实际上只使用表格来查看/排序。即使某些列可能全部都是整数或长整型,为这些列提供 Double 类是否会导致失败(除了可能需要分配更多空间之外)。我可以解析这些数字以查看列是否包含所有单一类型,但如果我真的不需要的话,这似乎需要大量工作。
谢谢, 杰夫
I have a JTable used to store numbers. I really only use the table for viewing/sorting. Is there a downfall (other than maybe needed to allocate more space) to giving the columns a class of Double even if some of the columns may have all ints or longs. I can parse the numbers to see if a column contains all of a single type, but that seems like a lot of work if I don't really need to.
thanks,
Jeff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在编写自己的
TableModel
,并重写getColumnClass()
方法。此外,您希望表格选择一个可以右对齐数字的渲染器,但不关心渲染差异。如果是这种情况,那么我建议返回
Number.class
,而不是特别费心将实际模型数据存储为 Double。I'm assuming that you're writing your own
TableModel
, and overriding thegetColumnClass()
method. And furthermore, that you want the table to pick a renderer that right-justifies numbers, but don't otherwise care about rendering differences.If that's the case, then I'd suggest returning
Number.class
, and not particularly bothering with storing the actual model data as Double.