Get column / row width / height of a GridPane?

While it’s obvious how to set the width / height of a column / row in a GridPane , how can I actually request these values?

+5
source share
3 answers

JavaFX8: there is a package protection method GridPane.getGrid to get the current row / column sizes in a two-dimensional double array. You can use reflection to get it. In mgr-protected environments this will not 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; } 
+2
source

Disclaimer : I extracted this from the question where the OP ( stefan.at.wpf ) answered it myself. Answers should not be contained in the question itself . Also, do not use Edit / Update: Questions / Answers should not record history .


You can add an empty HBox / VBox to the corresponding column / row of the GridPane and attach the listeners to the HBox / VBox widthProperty / heightProperty , but I'm still wondering if there is a way to directly get the width and height of the column / row in GridPane .

0
source

Javafx-8 now has a method called GridPane#impl_getCellBounds that will make GridPane#impl_getCellBounds work, although it is part of the internal API. (Not sure if this was also available in javafx-2)

Please note that, as @olmstov commented, the mentioned method has been removed and removed in subsequent versions of javafx. If there is a better way (compatible with the public API), it is recommended to use it instead of this alternative.

-1
source

All Articles