Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how get column index and row index in gridpane of javafx

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.

like image 631
java baba Avatar asked Jun 13 '13 09:06

java baba


People also ask

How does GridPane work in JavaFX?

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.

How do I get node from GridPane?

To retrieve the coordinates from a node, you just need to invoke the GridPane static methods getColumnIndex() and getRowIndex() .

How do you add a row to GridPane in Scene Builder?

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.

Which JavaFX layout pane lays out its children in a grid of columns and rows?

GridPane. The GridPane layout pane enables you to create a flexible grid of rows and columns in which to lay out nodes.


1 Answers

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.

like image 156
Shreyas Dave Avatar answered Nov 08 '22 16:11

Shreyas Dave