[英]How do I make a table adjust its size base on the total width of the columns?
Please look at this table. 请看这张桌子。 This is the Default Table where 8 columns are showing.
这是默认表 ,其中显示8列。
But take a look at this other table. 但是看看这张桌子。 This is the table with More Columns .
这是带有更多列的表。 But you can see that everything is so compact, what I expected is the horizontal scrollbar to appear.
但是您会看到一切都非常紧凑,我期望的是出现水平滚动条。
You change the behaviour through the JTable#setAutoResizeMode
method. 您可以通过
JTable#setAutoResizeMode
方法更改行为。
Passing it JTable.AUTO_RESIZE_OFF
will stop the table from automatically sizing the columns to "fit" the view area and will rely instead on the properties provided by the underlying TableColumnModel
将其传递给
JTable.AUTO_RESIZE_OFF
将阻止表自动调整列的大小以“适合”视图区域,而是依赖于基础TableColumnModel
提供的属性。
This will place a much greater responsibility for managing the column widths on you, but will provide you with the overall desired result that when the total columns width is greater then the viewable area, you will get the horizontal scroll bar 这将给您带来更大的责任来管理列宽,但是将为您提供总体期望的结果,即当总列宽大于可见区域时,您将获得水平滚动条
Use JTable with JScrollPane and rewrite the resolution window if possible. 将JTable与JScrollPane一起使用,并在可能的情况下重写分辨率窗口。
Reference: https://kodejava.org/how-do-i-create-a-scrollable-jtable-component/ 参考: https : //kodejava.org/how-do-i-create-a-scrollable-jtable-component/
https://www.javatpoint.com/java-jtable https://www.javatpoint.com/java-jtable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.