javafx-2 - 在图像中心插入文本

标签 javafx-2 javafx javafx-8

我有这段代码,它将图像插入边框 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/

相关文章:

java - "__ Cannot be resolved to a type"- JavaFX 无法在 Eclipse 中使用 e(fx)clipse 插件工作

java - Controller 的disableProperty和setDisable的低级绑定(bind)

JavaFx 2.0 : Controlling the Z-Order of Stage elements

layout - 我可以强制 JavaFX 的 GridPane 均匀分配空间吗?

java - CellFactory 与 CellValueFactory

java - 如何使用 java 实现类似 alt+tab 的功能?

java - 如何解决StringConverter ClassCastException?

fxml - 如何在 TreeTableView 中显示行的网格线

java - 如何设置JavaFX TextArea的高度和宽度?

java - 用于 DMG 背景的自定义插入式图标,用于 MacOSX 上的应用程序打包