Skip to main content

Fixed startx in GridBagLayout

No replies
bskaarup
Offline
Joined: 2003-06-17
Points: 0

When adding and removing components in a JPanel that uses GridBagLayout the components gets centeret by ArrangeGrid
info.startx = diffw/2 + insets.left;
info.starty = diffh/2 + insets.top;

When dynamically adding and removing lots of components the left margin moves from side to side making the leftmost components move around.
My users dont like this and I have tried to add a Box.createGlue to the right of my rightmost component, but it has a sideeffect. Without it it seems that GridBagLayout is able to fill the entire JPanel when resizing - with the gluebox it isnt as good.

Is there a way to set startx to a fixed value and if not why?