按钮中的graphic 可以是任何节点。 Shape 例如 Circle 是一个节点。
所以只需将按钮图形设置为形状即可。您甚至可以将许多形状放入容器(例如 VBox 或 StackPane)中,并将按钮的图形设置为容器,以便图形由许多形状组成。
这是一个示例 FXML 文件,您可以在 SceneBuilder 2 中复制和粘贴并加载。
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<VBox spacing="10.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Panic">
<graphic>
<Circle fill="RED" radius="8.0" stroke="BLACK"/>
</graphic>
</Button>
<Button maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="All OK">
<graphic>
<StackPane>
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="LEMONCHIFFON" height="15.0" stroke="BLACK"
strokeType="INSIDE" width="15.0"/>
<SVGPath
content="M 1.3657704,4.938667 C 1.1462945,5.1582921 1.1462945,5.5133282 1.3657704,5.7329533 L 3.7236648,8.0924507 C 3.9431407,8.3120765 4.2979355,8.3120765 4.5174113,8.0924507 L 9.5366913,3.0697579 C 9.7561672,2.8501328 9.7561674,2.4950969 9.5366913,2.2754716 L 8.6962538,1.4344625 C 8.4767779,1.2148374 8.121983,1.2148374 7.9025071,1.4344625 L 4.6107933,4.7284147 L 3.4902099,3.6070693 C 3.270734,3.3874441 2.9159392,3.387444 2.6964632,3.6070693 L 1.3657704,4.938667 z"
fill="GREEN"/>
</children>
</StackPane>
</graphic>
</Button>
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
</VBox>