Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1288 > unrolled thread
| Started by | "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:32 +0000 |
| Last post | 2011-04-27 15:32 +0000 |
| Articles | 14 — 8 participants |
Back to article view | Back to comp.lang.java.gui
GridBagLayout and changin "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Chris Smith" <chris.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Tom Hawtin" <tom.hawtin@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "SadRed" <sadred@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "SadRed" <sadred@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: GridBagLayout and cha "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
| From | "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | GridBagLayout and changin |
| Message-ID | <1174860473.305833.284620@n76g2000hsh.googlegroups.com> |
To: comp.lang.java.gui,comp.l
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?
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Chris Smith" <chris.smith@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <MPG.2070a65072e2ecc5989846@news.altopia.net> |
| In reply to | #1288 |
To: comp.lang.java.gui
Daniel Pitts <googlegroupie@coloraura.com> 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?
The latter. The GridBagLayout class makes a copy of the layout
constraints when the device is added. In fact, it's fairly common to
create just one GridBagConstraints object, and use it to add a large
number of components by just changing the few properties that differ
each time.
--
Chris Smith
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <aSCNh.151871$_w.125037@newsfe13.lga> |
| In reply to | #1288 |
To: comp.lang.java.gui
Daniel Pitts wrote:
> Say I have the following code:
>
> JPanel myPanel = new JPanel(new GridBagLayout());
> GridBagConstraints constaints = getConstraints();
What class does the method getConstraints() belong to?
> 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?
>
No. You will have to re-add it.
--
Knute Johnson
email s/nospam/knute/
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Tom Hawtin" <tom.hawtin@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <4606fe4e$0$8739$ed2619ec@ptn-nntp-reader02.plus.net> |
| In reply to | #1288 |
To: comp.lang.java.gui
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
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <1174867259.278111.167330@n59g2000hsh.googlegroups.com> |
| In reply to | #1291 |
To: comp.lang.java.gui
On Mar 25, 3:57 pm, Tom Hawtin <use...@tackline.plus.com> 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.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "SadRed" <sadred@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <1174868059.450411.39590@o5g2000hsb.googlegroups.com> |
| In reply to | #1288 |
To: comp.lang.java.gui
On Mar 26, 7:07 am, "Daniel Pitts" <googlegrou...@coloraura.com>
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?
You could try it yourself.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <1174873607.959458.240520@l77g2000hsb.googlegroups.com> |
| In reply to | #1293 |
To: comp.lang.java.gui
On Mar 25, 5:14 pm, "SadRed" <cardinal_r...@yahoo.co.jp> wrote:
> On Mar 26, 7:07 am, "Daniel Pitts" <googlegrou...@coloraura.com>
> 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?
>
> You could try it yourself.
I could, but that might have only proved that sometimes it works. I
was asking if it would always work... As I discovered, it won't ever
work, but there is a different way to do it that will always work.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "SadRed" <sadred@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <1174886341.549508.197350@b75g2000hsg.googlegroups.com> |
| In reply to | #1288 |
To: comp.lang.java.gui
On Mar 26, 7:07 am, "Daniel Pitts" <googlegrou...@coloraura.com>
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?
Why don't you try it yourself?
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <46075a2b$0$17150$4c368faf@roadrunner.com> |
| In reply to | #1288 |
To: comp.lang.java.gui
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?
>
You will have to remove it and re-add it. How is Java to know which
Object is supposed to have the new constraint if you don't re-add the
Object with that constraint? It could assume to apply that new
constraint property to the only Object in a JPanel if there is only one
in it but that wouldn't work for more than 1 Object in container and it
isn't a good way to do it anyway. It is bad design to need to
relocate/resize an Object after an event occurs. You should rethink how
you are presenting the interface to the user because the user should not
normally see new things appear when they do something; all the Objects
in the GUI should be visible, their sizes unchanging, and the unused
ones disabled until they are needed (with the enabling trigger being
your event).
As it is now, the line:
myPanel.add(new JLabel("Hello world"), constaints);
isn't going to do much because you aren't defining what your constraints
are although some of the properties do have default values. The default
for gridx is 'relative' which may not be what you want initially.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <1174891263.141820.9180@b75g2000hsg.googlegroups.com> |
| In reply to | #1296 |
To: comp.lang.java.gui
On Mar 25, 10:28 pm, Brandon McCombs <n...@none.com> 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?
>
> You will have to remove it and re-add it. How is Java to know which
> Object is supposed to have the new constraint if you don't re-add the
> Object with that constraint? It could assume to apply that new
> constraint property to the only Object in a JPanel if there is only one
> in it but that wouldn't work for more than 1 Object in container and it
> isn't a good way to do it anyway. It is bad design to need to
> relocate/resize an Object after an event occurs. You should rethink how
> you are presenting the interface to the user because the user should not
> normally see new things appear when they do something; all the Objects
> in the GUI should be visible, their sizes unchanging, and the unused
> ones disabled until they are needed (with the enabling trigger being
> your event).
Actually, I have four objects which would only trade places, and they
are similar enough that the change shouldn't bother users. Have you
ever played a game on Yahoo games? notice when you sit at a table,
your side becomes the southern most side. I'm basically emulating
that effect.
It is easier to move the components around than to change which model
each component is looking at. Either way, the effect would be the
same.
>
> As it is now, the line:
> myPanel.add(new JLabel("Hello world"), constaints);
>
> isn't going to do much because you aren't defining what your constraints
> are although some of the properties do have default values. The default
> for gridx is 'relative' which may not be what you want initially.
Hmm, I don't see how you think that my constraints object is unset. I
simply didn't copy the code that implemented getConstraints();
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Ian Wilson" <ian.wilson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <4607965f$0$22122$db0fefd9@news.zen.co.uk> |
| In reply to | #1288 |
To: comp.lang.java.gui
Daniel Pitts wrote:
> Say I have the following code:
OK, I shall ...
>
> 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?
>
Others have given the answer you were seeking. However I can't help
noticing that the code you quoted can never have the expected effect
since constaints != constraints :-)
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <1174928012.159533.87090@p77g2000hsh.googlegroups.com> |
| In reply to | #1298 |
To: comp.lang.java.gui
On Mar 26, 2:46 am, Ian Wilson <scoblo...@infotop.co.uk> wrote:
> Daniel Pitts wrote:
> > Say I have the following code:
>
> OK, I shall ...
>
>
>
> > 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?
>
> Others have given the answer you were seeking. However I can't help
> noticing that the code you quoted can never have the expected effect
> since constaints != constraints :-)
Did I surround that code with an sscce tag? I don't think so. :-)
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <t6udnSHBpLX4S5rbnZ2dnUVZ_uiknZ2d@comcast.com> |
| In reply to | #1288 |
To: comp.lang.java.gui
"Daniel Pitts" <googlegroupie@coloraura.com> wrote in message
news:1174860473.305833.284620@n76g2000hsh.googlegroups.com...
>
> 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.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: GridBagLayout and cha |
| Message-ID | <C6Sdnavp69ntRJrbnZ2dnUVZ_oytnZ2d@comcast.com> |
| In reply to | #1288 |
To: comp.lang.java.gui Oops, the OP was to cljp and cljg with followups to cljg, so I didn't see the answers already here. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web