简体   繁体   English

如何使表格根据列的总宽度调整其大小?

[英]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.

相关问题 如何使底部 Sheet 在不同的屏幕尺寸上调整其大小? - How to make the bottom Sheet adjust its size on different screen sizes? 在Vaadin 7中,使Horizo​​ntalSplitPanel调整其宽度以适应content- - Make HorizontalSplitPanel adjust its width to content- in Vaadin 7 如何在键盘应用程序中调整按钮大小? - How do I adjust Button size in Keyboard application? 如何使用GridBagLayout使JLabel 1列宽,然后使JTextField 2列宽(总宽度为3列) - How to use GridBagLayout to make a JLabel 1 column wide and then a JTextField 2 columns wide (for a total width 3 columns) 如何调整Label的宽度以适应其内容? - How to adjust Label's width to fit its content? 我们如何调整 p:commandbutton 的大小或宽度 - How can we adjust p:commandbutton size or width 如何获取Swing MetaWidget以动态调整其大小 - How to get the Swing MetaWidget to adjust its size dynamically 如何制作与文本大小完全相同的按钮? - How can I make a button exactly the same size of its text? 如何使数组大小可变? - How do I make a variable array size? 如何制作一个可变长度数组,根据输入调整其大小并显示最大和第二大数字? - How do I make a variable length array that adjusts its size depending on the input and displays the largest and second largest number?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM