Search code examples
javafxgridpane

JavaFX: How to shift elements in a GridPane?


Let me explain: lets say i have a GridPane 10x10 and in position row = 2 and col = 3 there is a Circle. I have a Button and I want that when the button is pressed, the circle shift to the right 1 step (1 coloumn) so its new position will be row = 2, col = 4. The question is: Is it a good idea to create a new class, extending circle and adding to it int actualRow; var int actualCol; ? So when I press the button, I will remove the element from (actualCol, actualRow) and placed it in (actualCol+1, actualRow) ?


Solution

  • IMHO, storing the GridPane row and column inside a class might not be a good idea, as it makes your class tightly bind with the GridPane leading to a bad design

    Moreover, the approach becomes more complicated when the number of Circles in your gridpane increases, under such scenario, you will have to keep a separate list of all the MyCircle objects, which is again an overhead