Reputation: 17654
While it's obvious how to set the width/height of a column/row in a GridPane
, how can I actually query these values?
Upvotes: 6
Views: 7624
Reputation: 1918
In javafx-8 there now is a method called GridPane#impl_getCellBounds
which will do the trick, although it is part of the internal API. (Not sure if this was also available in javafx-2)
Note, as commented by @olmstov the mentioned method is depricated and removed in later versions of javafx. If there is a better way (compatible with the public API) it is recommended to use that instead of this alternative.
Upvotes: 1
Reputation: 5831
Disclaimer: I extracted this from the question, where OP (stefan.at.wpf) self-answered it. Answers should not be contained in the question itself. Also don't use Edit/Update: Questions/Anwers don't need to record history.
One can add an empty HBox
/VBox
to the corresponding GridPane
column/row and attach listeners to the HBox
/VBox
widthProperty
/heightProperty
, still I am wondering if there is a way to directly get the width and height of a column / row in a GridPane
.
Upvotes: 1
Reputation: 61
JavaFX8: There is a pack protected method GridPane.getGrid
to get the current row/col sizes in a two dim double array.You could use reflection to acccess it. In environments with a security mgr, this won't work.
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;
}
Upvotes: 3