java - How can I access a control that's in a grid pane? -
i have defined grid pane in java fxml file follows:
<gridpane fx:id="grid" gridlinesvisible="true" prefheight="256" prefwidth="256"> ... <children> <label maxheight="1.8" maxwidth="1.8" /> <label maxheight="1.8" maxwidth="1.8" gridpane.columnindex="1" /> <label maxheight="1.8" maxwidth="1.8" gridpane.columnindex="2" /> <label maxheight="1.8" maxwidth="1.8" gridpane.rowindex="1" /> <label maxheight="1.8" maxwidth="1.8" gridpane.columnindex="1" gridpane.rowindex="1" /> <label maxheight="1.8" maxwidth="1.8" gridpane.columnindex="2" gridpane.rowindex="1" /> <label maxheight="1.8" maxwidth="1.8" gridpane.rowindex="2" /> <label maxheight="1.8" maxwidth="1.8" gridpane.columnindex="1" gridpane.rowindex="2" /> <label maxheight="1.8" maxwidth="1.8" gridpane.columnindex="2" gridpane.rowindex="2" /> </children> ... </gridpane>
the grid 3 x 3 , has label in each of cells. possible loop through grid , change text each label shown in pseudo code below:
for (cell : grid) { cell.label.settext("x"); }
can be
for ( node node : gridpane.getchildren() ) { (( label ) node).settext( "x" ); }
assuming gridpane.setgridlinesvisible( false );
however when gridpane.setgridlinesvisible( true )
, additional gridlines
(type of group
) added gridpane's children list. in case may check class types:
for ( node node : gridpane.getchildren() ) { if(node instanceof label) (( label ) node).settext( "x" ); }
note gridlinesvisible
property debugging purposes only. there other options style gridpane.
Comments
Post a Comment