TableModel 列区分数字类型

发布于 2024-08-18 09:03:56 字数 160 浏览 0 评论 0原文

我有一个用于存储数字的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月竹挽风 2024-08-25 09:03:56

我假设您正在编写自己的 TableModel,并重写 getColumnClass() 方法。此外,您希望表格选择一个可以右对齐数字的渲染器,但不关心渲染差异。

如果是这种情况,那么我建议返回 Number.class,而不是特别费心将实际模型数据存储为 Double。

I'm assuming that you're writing your own TableModel, and overriding the getColumnClass() 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文