如何组合字符在 Javafx 中创建图标?
How to combine characters to create icons in Javafx?
在 Windows 中,您可以组合字符来构建图标:
在 Javafx 中是否有等效的方法来为 Javafx 按钮创建图标?
(最好是 FXML)
编辑:
以下是我目前在 FXML 中添加按钮的方式:
<Button text="">
<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>
为了演示,我使用了这两张图片:
构造一个如下所示的按钮:
堆叠图像并用作按钮的图形节点:
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);
在 Windows 中,您可以组合字符来构建图标:
在 Javafx 中是否有等效的方法来为 Javafx 按钮创建图标?
(最好是 FXML)
编辑: 以下是我目前在 FXML 中添加按钮的方式:
<Button text="">
<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>
为了演示,我使用了这两张图片:
构造一个如下所示的按钮:
堆叠图像并用作按钮的图形节点:
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);