Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8100836

the ChangeListener is not generic and thus a cast is required in the event method

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • fx2.0
    • fx2.0
    • javafx
    • None
    • WXP, JavaFX 2.0 EA b20

      I'm porting my code to the new b20 / Property release and run into this:

      1. I have 42 ToggleButtons
      2. To each I register the same ChangeListener (instead of 42 separate)
      3. Inside the ChangeListener I want to find out which toggle button was the origin of the event

      class {
         private void x() {
                 ToggleButton lToggleButton = new ToggleButton();
                 lToggleButton.selectedModel().addChangeListener(iDayToggleButtonSelectedValueModelListener);
         }

         private ValueModelListener iDayToggleButtonSelectedValueModelListener = new ValueModelListener() {
             @Override
             public void handle(ObservableValue observableValue) {
                 BooleanProperty lBooleanProperty = (BooleanProperty)observableValue;
             }
      }

      My problems are:
      - I have to cast the ObservableValue to BooleanProperty to be able to access the value, that can't be right?!
      - There is no way I can find what ToggleButton was clicked?

      I would expect the addChangeListener to be generic;
         ...addChangeListener(ValueModelListener<BooleanProperty> ...)

      I would expect the ValueModelListener use its generics:
         public void handle(BooleanProperty observableValue)

            mheinrichs Michael Heinrichs (Inactive)
            tbee Tom Eugelink
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: