Eric Jiang
Eric Jiang

Reputation: 597

JLabel.setVisible(false) make other components' position change

I meet a relayout problem that is in my swing application I add four components (two JLabels, one JTextField and one table, each occupies one row) to a panel by using GridBagLayout, for some logic, I need to make one label visible true or false based on some conditions, but when I invoke setVisible(false) the components below this label will come up a little and when I invoke setVisible(true) they come down a little which makes the GUI flashing. Are there any methods which can make other components stick on the panel? Thanks.

Upvotes: 1

Views: 1710

Answers (2)

jzd
jzd

Reputation: 23629

Instead of setting the label visible or not, you could just change the text between the default and "". The Label would still stack the same height but no text would be visible.

Upvotes: 5

Sergey
Sergey

Reputation: 11908

How about TableLayout with fixed columns and rows?

Upvotes: 1

Related Questions