允许用户调整 JTable 列的大小

发布于 2024-09-04 23:00:18 字数 166 浏览 2 评论 0原文

我正在创建一个动态改变其宽度的表格。我还按时间添加列。我已将此表限制为滚动窗格。这里我在 JTable 中将自动调整大小设置为 false(否则它将从一开始就填充整个区域)。

我还使用 cellrenderer 将图像添加到单元格中。现在我需要允许用户调整该表列的大小。

有什么想法吗?

Im creating a table which is dynamically changing its width. And I add columns by time as well. And I have bounded this table to a scrollpane. Here I have set the auto resizing to false in the JTable (else it will fill the whole area from the beginning).

And I'm adding images to cells using cellrenderer as well. Now I need to allow users to resize this table columns.

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

街角卖回忆 2024-09-11 23:00:18

我不明白这个问题,默认情况下允许用户通过拖动列标题来调整列大小。

但是,如果您希望这种情况自动发生,那么您可以尝试使用 Table列调整器,可以自动调整列以适应数据的大小。

I don't understand the question, by default the user is allowed to resize the columns by dragging the header of the column.

However if you want this to happen automatically then you can try using the Table Column Adjuster, which can automatically adjust the columns to fit the size of the data.

回忆追雨的时光 2024-09-11 23:00:18

首先,只需更改 TableModel。您可以保留列调整大小,例如使用 setMaxWidth 设置单元格的最大宽度
或者只是选择适合您要求的正确模式。您可以在此处找到它们。

Well first of all - just change TableModel. You can leave column resizing on and for example set maximum width of cell by using setMaxWidth
Or just pick correct mode that fits your requirements. You can find them here.

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