losing the validation listener

Werner Lehmann lehmann at media-interactive.de
Mon Apr 8 02:51:28 PDT 2013

Hi Tom,

I did something similar: toggle group for toggles which correspond to 
enum members. This one assume that the toggles correspond to the enum 
members in their declared order. It also uses an invalidation listener 
and disabling/enabling a toggle keeps the listener functional as I just 
tested with a test application.

public class MintEnumToggleGroup<E extends Enum<E>> extends ToggleGroup
   public MintEnumToggleGroup(Class<E> enumClass)
     this.enumClass = enumClass;

     selectedToggleProperty().addListener(new InvalidationListener()
       public void invalidated(Observable observable)
         Toggle toggle = getSelectedToggle();
         E value = null;
         if (toggle != null)
           int ordinal =
           value = MintEnumToggleGroup.this.enumClass
         if (enumValue.get() != value)


    * Bidirectionally bindable property representing the enum member
    * of the selected toggle.
   public ObjectProperty<E> enumValueProperty() { return enumValue; }
   public E getEnumValue() { return enumValueProperty().get(); }
   public void setEnumValue(E value) { enumValueProperty().set(value); }

Looks similar to what you are doing. Let me know if you want to look at 
the full source (toggle group and testcase).


On 07.04.2013 21:28, Tom Eugelink wrote:
> Again some strange behavior I could use some pointers with. In JFXtras I've created an extended ToggleGroup which has a value property.
> https://github.com/JFXtras/jfxtras-labs/blob/2.2/src/main/java/jfxtras/labs/scene/control/ToggleGroupValue.java
> Basically what it does is listen to the selectedToggleProperty of ToggleGroup, and upon invalidation gets the user data associated with the now active toggle and puts that in the valueProperty. Simple, and now you can register and listen to the value of the toggle group. Which is exactly what I do in my basketball application by registering to the invalidated event.
>       toggleGroup.valueProperty().addListener(new InvalidationListener() {...});
> Now I have one very strange behavior; if I disable or hide the toggles, and then re-enable/show them again, the invalidation listener is no longer called. Some how it seems to have been removed from the listeners list. But the API documentation explicitly says it is a strong reference.
> http://docs.oracle.com/javafx/2/api/javafx/beans/Observable.html#addListener(javafx.beans.InvalidationListener)
> If I add a second dummy listener, then the first listener is not removed when disabled/hidden.
> It very much reeks like a garbage collection thing. Any suggestions?
> Tom

More information about the openjfx-dev mailing list