Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1296
| From | "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: GridBagLayout and cha |
| Message-ID | <46075a2b$0$17150$4c368faf@roadrunner.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <1174860473.305833.284620@n76g2000hsh.googlegroups.com> |
| Date | 2011-04-27 15:32 +0000 |
| Organization | TDS.net |
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
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web