Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to layout a rotated node correctly within a container?

Tags:

java

javafx-2

I want to add a Hyperlink to my JavaFX 2 application. This link is ment to be vertically at the very left or right side of my app, just like you see it with minimized and docked modules in many applications - for example IntelliJ IDEA.

It turns out that placing the node is hard even in SceneBuilder, as the container wether grows or changes the coordinates of the Hyperlink when i want to rotate it.

So my question is: How can i place one or more nodes that are rotated by wether 90 or 270 degrees within a container (preferrably VBox or AnchorPane) that's fix-sized?

like image 688
dajood Avatar asked Jan 15 '23 15:01

dajood


2 Answers

Place the rotated node in a Group - that way the layoutBounds of the Group will match the boundsInParent of the rotated Node. This is likely what you want because it means that the visual bounds of node are now used for layout purposes. This works for layout managers which automatically relocate nodes (such as VBox).

like image 134
jewelsea Avatar answered Jan 20 '23 05:01

jewelsea


You probably want do this in code, not in SceneBuilder. You can add a node to a parent (VBox or whatever) and apply a rotate transformation to it. Remember, all UI elements in JavaFX are just nodes in a scenegraph which can be transformed anyway you want.

See also the javadoc of Node, the paragraph about Transformations.

like image 24
Nicolas Mommaerts Avatar answered Jan 20 '23 03:01

Nicolas Mommaerts