允许用户调整 JTable 列的大小
我正在创建一个动态改变其宽度的表格。我还按时间添加列。我已将此表限制为滚动窗格。这里我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白这个问题,默认情况下允许用户通过拖动列标题来调整列大小。
但是,如果您希望这种情况自动发生,那么您可以尝试使用 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.
首先,只需更改 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.