【发布时间】:2013-04-16 23:47:11
【问题描述】:
虽然很明显如何在GridPane 中设置列/行的宽度/高度,但我如何实际查询这些值?
【问题讨论】:
虽然很明显如何在GridPane 中设置列/行的宽度/高度,但我如何实际查询这些值?
【问题讨论】:
JavaFX8:有一个包保护方法GridPane.getGrid 可以在两个暗淡的双精度数组中获取当前行/列的大小。您可以使用反射来访问它。在有安全经理的环境中,这不起作用。
public double[][] getCurrentGrid(GridPane gp) {
double[][] ret=new double [0][0];
try {
Method m=gp.getClass().getDeclaredMethod("getGrid");
m.setAccessible(true);
ret=(double[][])m.invoke(gp);
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
【讨论】:
在 javafx-8 中现在有一个名为 GridPane#impl_getCellBounds 的方法可以解决问题,尽管它是内部 API 的一部分。 (不确定 javafx-2 中是否也有此功能)
注意,正如 @olmstov 所评论的,所提到的方法在 javafx 的更高版本中已被弃用和删除。如果有更好的方法(与公共 API 兼容),建议使用该方法而不是此替代方法。
【讨论】:
免责声明:我从问题中提取了这一点,OP (stefan.at.wpf) 自行回答了它。 Answers should not be contained in the question itself。还有don't use Edit/Update: Questions/Anwers don't need to record history。
可以将空的HBox/VBox 添加到相应的GridPane 列/行并将侦听器附加到HBox/VBox widthProperty/heightProperty,我仍然想知道是否有是一种直接获取GridPane中的列/行的宽度和高度的方法。
【讨论】: