As in the subject - how one can get width and height of the javafx.scene.text.Text
control? This question refers to an example situation, where one want to create background for the Text
in a form of javafx.scene.shape.Rectangle
, whose size depends on the size of Text
.
Asked
Active
Viewed 7,723 times
2

bluevoxel
- 4,978
- 11
- 45
- 63
-
4`text.getBoundsInLocal().getWidth()` and `text.getBoundsInLocal().getHeight()` should do it. – James_D Jan 12 '16 at 18:49
2 Answers
0
Have you thought about using Label
? This allows for backgrounds, and the size of the label depends on the text.
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Label.html

Austin Brinkman
- 88
- 5
-
I'm using `Label` currently, but I'm curious about the possibility of getting values of parameters I've mentioned in my question. – bluevoxel Jan 12 '16 at 18:47
0
One thing to note is that if you are doing that before the component is visible, then the bounds may not be correct. I have had to handle it this way:
final Text text = new Text("This is my text");
text.applyCss();
//then get you height & width

purring pigeon
- 4,141
- 5
- 35
- 68