如何在JavaFX中指定字体大小时将fontawesomefx图标更改为矩形? [英] How to fix changing fontawesomefx icons to a rectangle when the font size is specified in JavaFX?

查看:282
本文介绍了如何在JavaFX中指定字体大小时将fontawesomefx图标更改为矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using fontawesomefx-8.9 and I have set their font size to 15px using

.glyph-icon {
  -fx-font-size: 15px;
}

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

Then I have created some FontAwesomeIconViews and embed them in some Buttons(JavaFX).

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

The issue I had to face is changing fontAwesome icons to a rectangle when hovering mouse over the button.

FXML文件位于下方(FXMLDocument,fxml)

FXML File is below(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)

CSS is file below(styles.css)

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

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

Just preview it on scene builder, the issue will appear!

如果您需要源代码,请从这里获取

If you want the source code, get it from here.

推荐答案

我有时会遇到同样的问题..我记得在我的css文件中添加了以下行问题。

i had the same issue sometime back .. i remember adding the following line to my css file fixed the issue.

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

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

Looks like your are using FontAwesome icon , may be try with the appropriate font family for that.

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

这篇关于如何在JavaFX中指定字体大小时将fontawesomefx图标更改为矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆