我打赌你在寻找其他的布局,但StackPane提供了这种类型的功能。
从教程:Working with Layouts
StackPane
的StackPane布局窗格地方所有节点的单 堆栈与上一节点的顶部增加每个新节点内。此 版式模型提供了一种将文字叠加在形状或图像上的简单方法,或与常用形状重叠以创建复杂形状。图1-6 显示了一个帮助图标,该图标通过在具有渐变背景的矩形的顶部 上堆叠问号创建。
从教程
例1-4创建堆栈窗格
StackPane stack = new StackPane();
Rectangle helpIcon = new Rectangle(35.0, 25.0);
helpIcon.setFill(new LinearGradient(0,0,0,1, true, CycleMethod.NO_CYCLE,
new Stop[]{
new Stop(0,Color.web("#4977A3")),
new Stop(0.5, Color.web("#B0C6DA")),
new Stop(1,Color.web("#9CB6CF")),}));
helpIcon.setStroke(Color.web("#D0E6FA"));
helpIcon.setArcHeight(3.5);
helpIcon.setArcWidth(3.5);
Text helpText = new Text("? ");
helpText.setFont(Font.font("Amble Cn", FontWeight.BOLD, 18));
helpText.setFill(Color.WHITE);
helpText.setStroke(Color.web("#7080A0"));
stack.getChildren().addAll(helpIcon, helpText);
stack.setAlignment(Pos.CENTER_RIGHT); // Right-justify nodes in stack
HBox.setHgrow(stack, Priority.ALWAYS); // Give stack any extra space
hbox.getChildren().add(stack); // Add to HBox from Example 1-2
其实代码,这正是我一直在寻找 - 我只是没有在看正确的地方!感谢那。 – berry120