当 JLabel 有多于一行时,JTabbedPane 不考虑更大的首选高度

JTabbedPane doesn't respect greater preferred height when JLabel has more than one line

我在 Java 摆动屏幕中遇到了一个奇怪的情况。基本上我有一个带有两个选项卡的 JTabbedPane。在第一个选项卡中有很多 JLabel,一个在另一个之上,在第二个选项卡中有一个 JXTable. This table is responsible for determine the height of the JTabbedPane in the screen since it has the greater height between the tabs (determined by JXTable.setVisibleRowCount),这几乎一直都很好。但是,当第一个选项卡中的任何标签包含太大而需要换行的文本时(它们是 HTML 标签),JTabbedPane 会调整大小以适应第一个选项卡所需的最小高度并切断第二个选项卡中 table 的内容。知道为什么会这样吗?

还没来得及开发一个Minimal, Complete, and Verifiable example,我就想通了这个问题。这完全是关于第二个选项卡中我的 table 的 JScrollPane 的 minimumSize,它没有设置。在我用相同的 getPreferredSize 值(下面的代码)定义最小尺寸后,它工作正常。

scrollPane.setMinimumSize(table.getPreferredSize());