gpt4 book ai didi

java - VBox(或 HBox)内的旋转对象

转载 作者:行者123 更新时间:2023-11-30 09:09:26 29 4
gpt4 key购买 nike

我有一个程序短片,可以将旋转对象放入 VBox 中。我希望 VBox 根据旋转调整其垂直尺寸。在以下示例中,文本对象不应接触:

enter image description here

但他们确实如此。生成它的代码如下:

package metcarob.com.soavisualise;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class TestAppForRotate extends Application {

@Override
public void start(final Stage primaryStage) throws Exception {

Group root = new Group();
Scene scene = new Scene(root);

primaryStage.setScene(scene);

VBox vbox = new VBox();
root.getChildren().add(vbox);

Group g = null;
Text t = null;
StackPane p = null;

for (int c=0;c<3;c++) {
g = new Group();
t = new Text("Test " + Integer.toString(c));
p = new StackPane();
p.getChildren().add(t);
p.setStyle("-fx-background-color: white; -fx-border-color: orange; -fx-border-width: 3;");
g.getChildren().add(p);
g.setRotate(c * 35);
vbox.getChildren().add(g);
}

primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}

在这个配置中我有组内 StackPane 内的文本整个组被旋转并添加到 VBox(在这个例子中,我需要橙色框和文本一起旋转)

关于如何让它发挥作用的任何想法?罗伯特

最佳答案

将旋转的节点包裹在未旋转的组中。

vbox.getChildren().add(new Group(g));

spacing

之所以有效,是因为 Group javadoc :

if transforms and effects are set directly on children of this Group, those will be included in this Group's layout bounds.

如果你想在 VBox 项之间有额外的固定空间,你可以使用 vbox.setSpacing正如 Rohan 的回答中所建议的那样。

关于java - VBox(或 HBox)内的旋转对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23062241/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com