我有这段代码,它将图像插入边框 Pane 的中心:
private static final ImageView iv;
static {
iv = new ImageView(StartPanel.class.getResource("/com/dx57dc/images/6.jpg").toExternalForm());
}
bpi.setCenter(iv);
现在我遇到了这个问题。我将此插入文本作为图像中心的标签。
Text inftx = new Text("基础设施");
我怎样才能做到这一点?
最佳答案
您可以使用 StackPane
执行所需的图像重叠。以下代码可用于您的示例:
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
tutorial :
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.
关于javafx-2 - 在图像中心插入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18165662/