FXML 图像透明度

FXML Image Transparency

我正在努力实现两个目标。

  1. 使图像相对于文本透明。
  2. 没有图像将文本挤压到右边。

      <Button fx:id="btn" layoutX="90.0" layoutY="14.0" mnemonicParsing="false" prefHeight="97.0" prefWidth="320.0" styleClass="root" text="Button">
        <graphic>
            <ImageView fitHeight="87.0" fitWidth="244.0">
                <image>
                    <Image url="@image.jpg"/>
                </image>
            </ImageView>
        </graphic>
    </Button>
    

非常感谢任何帮助。

你可以做的是使舞台透明,这样舞台上的所有东西都可以使用这种方法透明:stage.initStyle(StageStyle.TRANSPARENT)然后你也可以将场景设置为透明scene.setFill(Color.TRANSPARENT).同意这个答案,如果这解决了您的问题:)

the contentDisplay property 设置为 ContentDisplay.CENTER。这应该在与 Button:

一起使用的 graphic 之上绘制文本
<Button fx:id="btn" contentDisplay="CENTER" ...>
    ...
</Button>