How to get column index and row index in gridpane javafx

how to get column index and row index in gridpane javafx. see 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.

+4
source share
1 answer

You can get the row index and column index using the static methods getRowIndex () and getColumnIndex (), which are in the GridPane class.

 System.out.println("Row: "+ GridPane.getRowIndex(text1)); System.out.println("Column: "+ GridPane.getColumnIndex(text1)); 

See for reference: http://docs.oracle.com/javafx/2/api/javafx/scene/layout/GridPane.html#getRowIndex(javafx.scene.Node)

+6
source

Source: https://habr.com/ru/post/1485967/


All Articles