user1631306
user1631306

Reputation: 4470

GridBagLayout: changes alignment after adding checkbox

I have two classes which creates two different dialog box. Both the classes have same code, except one has additional lines of code, which creates a checkbox

first Class, with Checkbox

enter image description here

Second Class, without Checkbox

enter image description here

There is slight alignment difference in "save" button. How can I fix this.

Upvotes: 4

Views: 65

Answers (2)

user1631306
user1631306

Reputation: 4470

I had to adjust the row height as the checkbox was taller than the row and was pushing the third row downward( Thanks to Ingrid Biery). so I changed the 2nd row height from 25 to 30 and it worked.

Upvotes: 0

Ingrid Biery
Ingrid Biery

Reputation: 90

Is there a particular reason you're using fixed row and column sizes? One of the great features of GridBagLayout is its ability to center/align and fill. This also tends to make things look better on different screen sizes, different fonts, etc.

To answer your specific question, my guess is that the checkbox is taller than the row you're putting it into, pushing the next row down.

When I debug GBL, I often set row/column background colors to different things and print out (or view in a debugger) sizes of the things I'm trying to fit into the container.

Upvotes: 1

Related Questions