Theo Theo - 1 year ago 174
Java Question

JavaFX 3D text rotation

I am a newcomer to javaFX-3D and I want to view simple 3D shapes with labels, such as node numbers etc. I've started from oracle's MoleculeSampleApp and I am trying to add text. Thus far I have arrived at this:

Axes with text

The text has been added as follows:

Text t = new Text("Hello world");
t.setFont(Font.font("Calibri", FontWeight.BOLD, 30));
t.translateXProperty().set(125 + 10);
t.translateYProperty().set(125 + 10);
Xform from = new Xform();

As soon as I start rotating the view, the text also flips all over and it becomes unreadable. Is there a way to make the text not rotate in all directions? Ideally the text should always be displayed like normal "2D" text, while moving along with its associated 3D object as the view is adjusted (zoom, rotate, etc.).

Answer Source

After a while I settled on using Tooltips instead. This is not exactly what I had in mind but it displays the text correctly when the mouse hovers over the Shape. An example is as follows:

Sphere ball= new Sphere(30/2);
Tooltip t = new Tooltip(tooltip);
            Tooltip.install(ball, t);