dajood
dajood

Reputation: 4050

How to layout a rotated node correctly within a container?

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?

Upvotes: 4

Views: 889

Answers (2)

jewelsea
jewelsea

Reputation: 159291

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).

Upvotes: 8

Nicolas Mommaerts
Nicolas Mommaerts

Reputation: 3263

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.

Upvotes: 1

Related Questions