Re: GridBagLayout and changing constraints objects.




"Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx> wrote in message
news:1174860473.305833.284620@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Say I have the following code:

JPanel myPanel = new JPanel(new GridBagLayout());
GridBagConstraints constaints = getConstraints();
myPanel.add(new JLabel("Hello world"), constaints);

And then later (as a result of an Event), I do something like
constraints.gridx = 3;
myPanel.revalidate();

Will this have the expected effect, or do I need to remove the old
label, and re-add it with the new constraints?

It will have no effect. Normally you change the (single) constraints
object between adding components. There is no need to create
multiple constraints objects. To change after creation, I assume you
can use GridBagLayout.setConstraints(). You could use
GridBagLayout.getConstraints(), make the change, then use
setConstraints() to avoid storing the constraints object.


.