Search code examples
javaswingswingx

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


I am facing a strange situation in a Java Swing screen. Basically I have a JTabbedPane with two tabs. In the first tab there is a lot of JLabels, one above the other, and in the second tab there is a 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), and this works just fine almost all the time. However, when any of the labels in the first tab contains a text too big that requires the line to break (they are HTML labels), the JTabbedPane resizes to fit the minimum height required by the first tab and cuts off the content of the table in the second tab. Any ideas why this happens?


Solution

  • Before I had time to develop a Minimal, Complete, and Verifiable example, I've figured out the problem. It was all about the minimumSize of my table's JScrollPane in the second tab, which wasn't set. After I have defined the minimum size with the same value of getPreferredSize (code below), it worked fine.

    scrollPane.setMinimumSize(table.getPreferredSize());