javafx的gridpane中如何获取列索引和行索引 [英] how get column index and row index in gridpane of javafx
本文介绍了javafx的gridpane中如何获取列索引和行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在JavaFX的GridPane
中获取列索引和行索引.看下面的代码
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);
当鼠标在 text1 上输入时,我想获取 GridPane 的列索引和行索引
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
}
});
请告诉我.
推荐答案
您可以使用静态方法 getRowIndex()
和 getColumnIndex()获取行索引和列索引code> 位于
GridPane
类中.
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));
查看参考.
这篇关于javafx的gridpane中如何获取列索引和行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文