在图像的中心插入文本 [英] Insert text at the center of a image
问题描述
我有这个代码将Image插入borderpane的中心:
I have this code which inserts Image into the center of a borderpane:
private static final ImageView iv;
static {
iv = new ImageView(StartPanel.class.getResource("/com/dx57dc/images/6.jpg").toExternalForm());
}
bpi.setCenter(iv);
现在我遇到了这个问题。我将此插入文本作为图像中心的标签。
And now I have this problem. I have this insert text as a label at the center of the image.
文本inftx =新文本(基础结构);
Text inftx = new Text("Infrastructure");
我怎么做?
推荐答案
你可以使用 StackPane
执行所需的图像重叠。可以在您的示例中使用以下代码:
You can use a StackPane
to performed the desired image overlap. The following code can be used on your example:
private static final ImageView iv;
static {
iv = new ImageView(StartPanel.class.getResource("/com/dx57dc/images/6.jpg").toExternalForm());
Text inftx = new Text("Infrastructure");
StackPane pane = new StackPane();
pane.getChildren().add(iv);
pane.getChildren().add(inftx);
pane.setAlignment(Pos.CENTER);
}
了解 StackPane
教程:
StackPane布局窗格将所有节点放在一个堆栈中,每个新节点都添加在上一个节点的顶部。此布局模型提供了一种在形状或图像上叠加文本或重叠常见形状以创建复杂形状的简便方法。
The StackPane layout pane places all of the nodes within a single stack with each new node added on top of the previous node. This layout model provides an easy way to overlay text on a shape or image or to overlap common shapes to create a complex shape.
这篇关于在图像的中心插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!