Hi Randahl,

you should override your Skin's dispose() method that removes the label.

Possible reasons I can imagine why JavaFX does not clear the child list itself:
1. The control could have some children on it's own, which shouldn't
be deleted when applying a skin. This will be the case for a control
that does not have a default skin.
2. Some third party code may add some nodes (e.g. a lightweight popup
or a "close" button) to your control. These should not be removed when
switching skins either.

Regards,
Tomas

On Wed, Jun 11, 2014 at 9:57 AM, Randahl Fink Isaksen <rand...@rockit.dk> wrote:
> I have noticed that if I create a skin which adds a label like this
>
>         public MySkin(MyControl control) {
>                 super(control);
>                 pane.getChildren().add(label);
>                 getChildren().add(pane);
>         }
>
> the label is actually added twice in my application. I suspect this is 
> because I am switching style sheets during startup, which means my 
> createDefaultSkin method might be invoked twice.
>
> I found out, I can easily solve this by changing my code to using a 
> getChildren().setAll(label) rather than getChildren().add(label), but I am 
> surprised that JavaFX would not by itself clear the control’s children when 
> applying a new skin.
>
> Has anyone else experienced this?
>
> Thanks
>
> Randahl

Reply via email to