I have a really hard design problem in my swing application. Generally Speaking, I have a JTable and a JLabel to display. The label is right below the table.
- When the height of these two components doesn’t exceed a threshold, then the table and label displays as normal. Then height of these two components will increase as the number of records filled in the table increases.
- When the height of these two components exceeds a threshold, I want there is a scroll bar in the table and the height of these two components will be the threshold.
Is this design Possible?
Swing layout don’t automatically re-layout when a preferred size changes, you’ll have to call revalidate (best probably with a TableModelListener which checks if the row count has changed). You also need a layout which sizes the component according to its preferred size, BorderLayout does that for the component in the borders (but not for the one in the center. For a different manager you’ll need GridBag or better Mig-/Form- or Table (third party) Layout