如何在JavaFX中指定字体大小时将fontawesomefx图标更改为矩形?

Lak*_*ana 2 css java javafx font-awesome

我正在使用fontawesomefx-8.9并且我已将其字体大小设置为15px使用

.glyph-icon {
  -fx-font-size: 15px;
}
Run Code Online (Sandbox Code Playgroud)

然后我创建了一些FontAwesomeIconViews并将它们嵌入到一些Buttons(JavaFX)中.

我不得不面对的问题是将鼠标悬停在按钮上时将fontAwesome图标更改为矩形.

在此输入图像描述

FXML文件如下(FXMLDocument,fxml)

<?xml version="1.0" encoding="UTF-8"?>

<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" stylesheets="@styles.css" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.111" fx:controller="test_fontawesome.FXMLDocumentController">
    <children>
        <Button fx:id="button" contentDisplay="TOP" layoutX="44.0" layoutY="41.0" onAction="#handleButtonAction" text="Click Me!" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="40.0">
         <graphic>
            <FontAwesomeIconView fill="BLUE" glyphName="CUT" />
         </graphic></Button>
        <Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
      <Button fx:id="button1" contentDisplay="TOP" layoutX="183.0" layoutY="41.0" onAction="#handleButtonAction" text="Click Me!" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="40.0">
         <graphic>
            <FontAwesomeIconView fill="BLUE" glyphName="PLUS" />
         </graphic>
      </Button>
    </children>
</AnchorPane>
Run Code Online (Sandbox Code Playgroud)

CSS是下面的文件(styles.css)

.root {
    -fx-font-size: 12px ;
}
Run Code Online (Sandbox Code Playgroud)

只需在场景构建器上预览,就会出现问题!

如果您需要源代码,请从此处获取.

use*_*883 7

我有时回到同一个问题..我记得在我的css文件中添加以下行修复了这个问题.

.glyph-icon{ -fx-font-family:"Material Design Icons"; }
Run Code Online (Sandbox Code Playgroud)

看起来您正在使用FontAwesome图标,可能会尝试使用相应的字体系列.

  .glyph-icon{ -fx-font-family:"FontAwesome"; }
Run Code Online (Sandbox Code Playgroud)