为了图标化我的应用程序,我决定使用 ControlFX 的 Font awesome 支持。
我尝试在 Code 和 FXML 中使用它,结果只有“GEAR”图标有效。
那么,是什么导致其他图标不显示?
她是 FXML 文件的代码:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import org.controlsfx.glyphfont.Glyph?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="testController">
<children>
<Button mnemonicParsing="false" text="Button" >
<graphic>
// The Gear icon works perfectly
<Glyph fontFamily="FontAwesome" icon="GEAR"/>
<Glyph fontFamily="FontAwesome" icon="SEARCH"/>
</graphic>
</Button>
</children>
</fx:root>
我还想在它工作后更改图标的颜色。
最佳答案
您似乎希望在一个 JavaFX Button 元素中包含两个图形。根据docs , 这是不可能的。
The button control can contain text and/or a graphic.
Button类的方法也说明一个按钮最多只能设置一个图形。
鉴于“GEAR”和“SEARCH”之间固有的语义差异,我相信您可能需要两个按钮。尝试:
...
<children>
<Button mnemonicParsing="false" text="Button" >
<graphic>
// the gear graphic
<Glyph fontFamily="FontAwesome" icon="GEAR"/>
</graphic>
</Button>
<Button mnemonicParsing="false" text="Search" >
<graphic>
// the search graphic
<Glyph fontFamily="FontAwesome" icon="SEARCH"/>
</graphic>
</Button>
</children>
...
关于javafx-8 - ControlsFX 字体 Awesome 不显示图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37594230/