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.)
