Search code examples
javajavafxfxml

How to put multiple TilePane in a group/list in JavaFx or FXML?


I've crumbled the internet to solve my problem but nothing..., So i have a list of TilePane down here

     <children>
                <TilePane fx:id="a0" onMouseClicked="#ma0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: black;" />
                <TilePane fx:id="b0" onMouseClicked="#mb0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: black;" GridPane.columnIndex="1" />
                <TilePane fx:id="c0" onMouseClicked="#mc0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: black;" GridPane.columnIndex="2" />
                <TilePane fx:id="d0" onMouseClicked="#md0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: black;" GridPane.columnIndex="3" />
                <TilePane fx:id="a1" onMouseClicked="#ma1" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: black;" GridPane.rowIndex="1" />
    </children>

So simply what i want to do is when i click a Button all those Tiles set to disabled all at once! easy right?

In case you didn't get my point... how do i give all these tiles an ID so this ID will represent all those tales "And it must interact as a tile, for example when i do Id.setVisible(true); it will effect all the tiles!" Thanks everyone.

maybe not the exact way as i described it but u get the point:)


Solution

  • why not give id to parent of this tiles, and then just do something like this

     pane.getChildren().forEach(node -> node.setDisable(true));
    

    and in case you have others childrens in pane - either use "instance of" in forEach, or just group this tiles in another node same way, in Group for example.