JavaFX: creating custom data attributes for nodes
I currently need custom attributes, which I can get at any time Is there any way to create custom data attributes for nodes and get these values in JavaFX?
Let's suppose I have the following buttons
<Button text="Im a button" fooBar="I hold some value" />
be similar to: https://developer.mozilla.org/de/docs/Web/Guide/HTML/Using_data_attributes
Now in HTML, I can simply do the following:
<div id="example" data-foobar="I hold some value"></div>
Then I can easily get such data:
document.getElementById("example").dataset.foobar;
Edit: I need multiple data attributes of a node, because the node can save all kinds of information
Solution
Data can be stored in the properties observable map of a node
Node node = ... node.getProperties().put("foo","bar"); ... Object foo = node.getProperties().get("foo");
Note, however, that some layout attributes also use this mapping, so attribute names like JavaFX attributes / "static" attributes should not be used as keys To ensure that you can create a custom key class, if you pass an object of another type as a parameter to equals, the class will not return true