Paste text in the center of the image

I have this code that inserts an image in the center of the border area:

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 in the center of the image.

Text inftx = new text ("Infrastructure");

How can i do this?

+4
source share
1 answer

You can use StackPane to perform the desired image match. The following code can be used in 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); } 

As the StackPane tutorial reported:

The StackPane layout panel pushes all nodes on the same stack with each new node added on top of the previous node. This mock model provides an easy way to overlay text on a shape or image or overlap common shapes to create a complex shape.

+5
source

Source: https://habr.com/ru/post/1496349/


All Articles