Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get event source from value property changed handler?

979248May 15 2013 — edited May 17 2013
I am relatively new to JavaFX, so perhaps this is an easy question to answer. I am creating in Java code several (e.g., 5) ChoiceBox instances. I add a handler for when the value of the ChoiceBox changes. My code:
ChoiceBox<String> rpmSelector = new ChoiceBox<>();
ObservableList<String> rpmSelectorItems = FXCollections.observableArrayList();
rpmSelectorItems.add(ALL_RPM);
for (Double engSpeed : engSpeeds) {
    rpmSelectorItems.add(String.format("%.0f", engSpeed.doubleValue()));
}
rpmSelector.setItems(rpmSelectorItems);
rpmSelector.getSelectionModel().selectFirst();
        
rpmSelector.valueProperty().addListener(new ChangeListener<String>() {
    @Override
    public void changed(ObservableValue<? extends String> obsValue,
            String oldValue, String newValue) {
       // How can I get the ChoiceBox that was the source of this event?
    }
});
My question is: in the "changed" method, how do I determine which of the ChoiceBox instances had its value changed?

Thanks!

Chris

Edited by: 976245 on May 15, 2013 1:05 PM

Edited by: 976245 on May 15, 2013 1:05 PM
This post has been answered by jsmith on May 15 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 14 2013
Added on May 15 2013
6 comments
304 views