how get column index and row index in GridPane
of JavaFX. see the code below
Text text1 = new Text("Text 1");
Text text2 = new Text("Text 2");
StackPane root = new StackPane();
GridPane gridPane = new GridPane();
gridPane.add(text1, 0, 0);
gridPane.add(text2, 1, 0);
When Mouse Entered On text1 I want to get the column index and row index of GridPane
text1.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
//want to get column index =0 and row index=0
}
});
Please let me know.
GridPane lays out its children within a flexible grid of rows and columns. If a border and/or padding is set, then its content will be layed out within those insets. A child may be placed anywhere within the grid and may span multiple rows/columns.
To retrieve the coordinates from a node, you just need to invoke the GridPane static methods getColumnIndex() and getRowIndex() .
This feature exists in the JavaFX Scene Builder by right clicking on the GridPane and selecting GridPane, then it will show a list of options: Add Row Above, Add Row Below, Add Column After, Add Column Before.
GridPane. The GridPane layout pane enables you to create a flexible grid of rows and columns in which to lay out nodes.
You can get the row index and column index by utilising the static methods getRowIndex()
and getColumnIndex()
which are located in the GridPane
class.
System.out.println("Row: " + GridPane.getRowIndex(text1));
System.out.println("Column: " + GridPane.getColumnIndex(text1));
See for the reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With