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/set FX:ID values using FXML?

J. IshikawaJun 23 2013 — edited Jun 24 2013

Hi!

I have a FXML-file with a group of many similar elements (e.g. checkboxes). Those elements use the same CSS-Styles, therefore they all have to have the same ID-value (e.g. "checkboxCSS") , but different and unique FX:ID values (e.g. "checkboxFXID_1" ... "checkboxFXID_999"). All those checkbox are connected to the same method (#someAction) in the controller class.

<Checkbox onAction="#someAction" id="checkboxCSS" fx:id="checkboxFX1" text="1" />

<Checkbox onAction="#someAction" id="checkboxCSS" fx:id="checkboxFX2" text="2" />

...

<Checkbox onAction="#someAction" id="checkboxCSS" fx:id="checkboxFX999" text="999" />

Inside the controller class, I would like to determine the event.source (FX:ID), so I can know which checkbox has been clicked by the user.  But it seems, I can only get the type and the ID-value, but not the fx:id value.

Here is what I tried to use...

@FXML private void someAction(ActionEvent event) { System.out.println(event.getSource()); }

And the corresponding output...

CheckBox[id=checkboxCSS, styleClass=check-box]

Best regards,

J. Ishikawa

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 22 2013
Added on Jun 23 2013
3 comments
5,491 views