gpt4 book ai didi

java - 当在 JavaFX 中指定字体大小时,如何修复将 fontawesomefx 图标更改为矩形的问题?

转载 作者:行者123 更新时间:2023-12-02 07:53:49 25 4
gpt4 key购买 nike

我使用的是 fontawesomefx-8.9,并且我已使用

将其字体大小设置为 15px
.glyph-icon {
-fx-font-size: 15px;
}

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

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

enter image description here

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>

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

.root {
-fx-font-size: 12px ;
}

只要在场景生成器上预览一下,问题就会出现!

如果您想要源代码,请从 here 获取.

最佳答案

我曾经遇到过同样的问题..我记得将以下行添加到我的 css 文件中解决了该问题。

.glyph-icon{ -fx-font-family:"Material Design Icons"; }

看起来您正在使用 FontAwesome 图标,可以尝试使用适当的字体系列。

  .glyph-icon{ -fx-font-family:"FontAwesome"; }

关于java - 当在 JavaFX 中指定字体大小时,如何修复将 fontawesomefx 图标更改为矩形的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41945099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com