You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Bill van Melle <bi...@gmail.com> on 2011/01/20 23:29:01 UTC

GridPane#clear doesn't

I have a GridPane for which I change the row/column arrangement when the
window resizes.  If GridPane components had attached properties for their
grid coordinates, I'd just change the properties.  But instead I guess I
have to clear the pane and lay it out afresh, building it up row by row
(which, may I say, is a little bit tedious in comparison to the WPF approach
to containers).  I have all the components already pre-built and stored in a
master list, so I thought I could just do

  pane.clear();
  doMyGridLayout(pane, components);

However, when I do that, I get an exception in
GridPane$Row.insert: "Component already has a parent."

So instead of calling clear, I have to do something like this:

RowSequence gridRows = pane.getRows();
gridRows.remove(0, gridRows.getLength());

as, apparently, RowSequence does know how to unparent its children (not that
this is so painful -- I initially feared I'd have to remove my components
one by one).

Am I missing something, or did GridPane forget to override clear() and do
something reasonable?

(I haven't tried it, but I'm wondering if the same question could be asked
of TablePane.)

Re: GridPane#clear doesn't

Posted by Greg Brown <gk...@verizon.net>.
> Am I missing something, or did GridPane forget to override clear() and do something reasonable?

I think that's probably it. I suspect you'll find a similar problem with most containers. We override remove() but not clear(). Good catch.





Re: GridPane#clear doesn't

Posted by Greg Brown <gk...@verizon.net>.
I think all three names are clear enough (no pun intended). The problem is that Container implements Sequence, which carries a different implication for clear(). I suspect that it would not be as confusing if Container *had* a component collection, rather than *being* a component collection.

G

On Jan 21, 2011, at 3:55 PM, Bill van Melle wrote:

> On Fri, Jan 21, 2011 at 6:17 AM, Greg Brown <gk...@verizon.net> wrote:
> I just realized that the clear() method is doing exactly what it is supposed to. clear() doesn't actually have anything to do with the child components - it is used for data binding (it is analogous to load() and store(), but "clears" the bound content).
> 
> Wow, what a bad name!  Let's see, the very familiar ArrayList has a getLength() method, which returns the number of elements, and a clear() method, which removes them all.  Container has a getLength() method, which returns the number of components, and a clear() method, which, um, does something funky with bindings.
> 
> Not that "load" and "store" are great names, either.  Way too brief for what they're doing.  Oh well, I guess we're stuck with them now.


Re: GridPane#clear doesn't

Posted by Bill van Melle <bi...@gmail.com>.
On Fri, Jan 21, 2011 at 6:17 AM, Greg Brown <gk...@verizon.net> wrote:

> I just realized that the clear() method is doing exactly what it is
> supposed to. clear() doesn't actually have anything to do with the child
> components - it is used for data binding (it is analogous to load() and
> store(), but "clears" the bound content).


Wow, what a bad name!  Let's see, the very familiar ArrayList has a
getLength() method, which returns the number of elements, and a clear()
method, which removes them all.  Container has a getLength() method, which
returns the number of components, and a clear() method, which, um, does
something funky with bindings.

Not that "load" and "store" are great names, either.  Way too brief for what
they're doing.  Oh well, I guess we're stuck with them now.

Re: GridPane#clear doesn't

Posted by Greg Brown <gk...@verizon.net>.
I just realized that the clear() method is doing exactly what it is supposed to. clear() doesn't actually have anything to do with the child components - it is used for data binding (it is analogous to load() and store(), but "clears" the bound content). 

You are probably getting that exception because you are trying to re-add components to your grid pane, but they were never actually removed.

G

On Jan 20, 2011, at 5:29 PM, Bill van Melle wrote:

> I have a GridPane for which I change the row/column arrangement when the window resizes.  If GridPane components had attached properties for their grid coordinates, I'd just change the properties.  But instead I guess I have to clear the pane and lay it out afresh, building it up row by row (which, may I say, is a little bit tedious in comparison to the WPF approach to containers).  I have all the components already pre-built and stored in a master list, so I thought I could just do
> 
>   pane.clear();
>   doMyGridLayout(pane, components);
> 
> However, when I do that, I get an exception in GridPane$Row.insert: "Component already has a parent."
> 
> So instead of calling clear, I have to do something like this:
> 
> 	RowSequence gridRows = pane.getRows();
> 	gridRows.remove(0, gridRows.getLength());
> 
> as, apparently, RowSequence does know how to unparent its children (not that this is so painful -- I initially feared I'd have to remove my components one by one).
> 
> Am I missing something, or did GridPane forget to override clear() and do something reasonable?
> 
> (I haven't tried it, but I'm wondering if the same question could be asked of TablePane.)