When making individual components of a layout managed by GridBagLayout invisible, the arrangement of the remaining components in the layout keeps changing. The GridBagLayout appears to "collapse" cells with invisible components, causing other components to change positions. This is a highly annoying behaviour, and I've been looking for a way to keep it from doing that.
One method I've tried is by adding a spacer to the same cell, with a fixed size equal to the preferred size of the component that may be hidden, but if that preferred size ever were to change, it would be a lot of trouble to keep the spacer in sync. Is there a better way?
Actually, it wouldn't be so bad if the GridBagLayout would really completely disregard cells with invisible components, but it still takes the cell's insets into account, so if you have a layout of input fields and used the insets to neatly arrange them with regular gaps in between, then hiding one component in the middle removes it from the layout but leaves the gap, which usually means the surrounding components flow together, but with an ugly double-wide gap between them...