3

为了使我的应用程序图标化,我决定使用 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>

我还想在让它工作后改变图标的​​颜色。

4

1 回答 1

5

您似乎想要在一个 JavaFX Button 元素中包含两个图形。根据文档,这是不可能的。

按钮控件可以包含文本和/或图形。

Button 类的方法也表明最多只能将一个图形设置为一个按钮。

鉴于“齿轮”和“搜索”之间固有的语义差异,我相信您可能需要两个按钮。尝试:

...
<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>
...
于 2016-11-26T02:24:43.757 回答