gpt4 book ai didi

java - 如何在Javafx中组合字符来创建图标?

转载 作者:行者123 更新时间:2023-11-30 05:29:01 24 4
gpt4 key购买 nike

在 Windows 中,您可以组合字符来构建图标:

https://learn.microsoft.com/en-us/windows/uwp/design/style/segoe-ui-symbol-font#layering-and-mirroring

enter image description here

在 Javafx 中是否有等效的方法来为 Javafx 按钮创建图标?

(最好是 FXML)

编辑:以下是我目前在 FXML 中添加按钮的方法:

<Button text="&#xE700;">
<font>
<Font name="Segoe MDL2 Assets" size="14.0" />
</font>
</Button>

答案:

在下面的答案的帮助下,我使用了这个 FXML:

<Button>
<graphic>
<StackPane style="-fx-background-color: transparent;">
<Label text="A" />
<Label text="B" />
</StackPane>
</graphic>
</Button>

最佳答案

为了演示它,我使用这两个图像:

enter image description here enter image description here


构建一个如下所示的按钮:

enter image description here

堆叠图像并用作按钮的图形节点:

private static final String[] images = {
"https://i.imgur.com/g52UeNO.png",
"https://i.imgur.com/kvHOLJ4.jpg",
};

ImageView imageView1 = new ImageView(images[0]);
ImageView imageView2 = new ImageView(images[1]);
StackPane sp = new StackPane(imageView1, imageView2);
Button button = new Button("", sp);

编辑:要堆叠字符,请使用:

Text t1 = new Text(Character.toString('O'));
t1.setFont(Font.font ("Verdana", 20));
t1.setFill(Color.RED);
Text t2 = new Text(Character.toString('x'));
t2.setFont(Font.font ("Verdana", 12));
t1.setFill(Color.BLUE);
StackPane sp = new StackPane(t1, t2);
Button button = new Button("", sp);

关于java - 如何在Javafx中组合字符来创建图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57940345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com