Skip to content
Advertisement

Javafx Is there a better way to add myObjects to GridPane?

i was searching for answer and trying so many options. Finally i found way to pass my own javaxf object to GridPane. But I still think there is a better way to this than I am doing. So here is my code: Main:

JavaScript
JavaScript

By better way I mean, that there might be other way than passing GridPane and int x, int y indexes. I still wanna use GridPane.

Thank you for any Help I am new to this

Advertisement

Answer

As @JimD already commented, embedding a reference to the parent of a Node into a node is bad practice. There’s nothing special about the Rectangles other than the event handler which toggles the colour. Assuming that you don’t want to access the “selected” state of the Rectangles, you can ditch the custom class altogether.

The following code does everything that your sample does, except the call to the [not included] “ShelfShowUp.display(“KOKOS”, 7)” :

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement