java javafx的gridpane中如何获取列索引和行索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17083974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 00:55:08  来源:igfitidea点击:

how get column index and row index in gridpane of javafx

javajavafx-2javafxjavafx-8

提问by java baba

how get column index and row index in GridPaneof JavaFX. see the code below

如何在GridPaneJavaFX 中获取列索引和行索引。看下面的代码

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 上输入时,我想获取 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.

请告诉我。

回答by Shreyas Dave

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

您可以使用位于 GridPane 类中的静态方法 getRowIndex() 和 getColumnIndex() 来获取行索引和列索引。

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)

请参阅参考:http: //docs.oracle.com/javafx/2/api/javafx/scene/layout/GridPane.html#getRowIndex(javafx.scene.Node)