Re: GridBagLayout and changing constraints objects.
- From: "Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx>
- Date: 25 Mar 2007 17:00:59 -0700
On Mar 25, 3:57 pm, Tom Hawtin <use...@xxxxxxxxxxxxxxxxx> wrote:
Daniel Pitts wrote:
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 wont have any affect. The constraints object is cloned. Indeed it is
normal to use one constraints object to add many components.
To change the constraints for a component, just call
LayoutManager[2].addLayoutComponent.
Tom Hawtin
Thanks to everyone who replied.
I should have RTFM. Actually, its RTFA, isn't it?
GridBagLayout.setConstraints is what I need to use. :-)
Cheers,
Daniel.
.
- References:
- Re: GridBagLayout and changing constraints objects.
- From: Tom Hawtin
- Re: GridBagLayout and changing constraints objects.
- Prev by Date: Re: GridBagLayout and changing constraints objects.
- Next by Date: Re: GridBagLayout and changing constraints objects.
- Previous by thread: Re: GridBagLayout and changing constraints objects.
- Next by thread: Re: GridBagLayout and changing constraints objects.
- Index(es):
Relevant Pages
|