FontAwesomeFX - 仅显示矩形

时间:2015-07-07 14:41:01

标签: javafx

我正在尝试在我的JavaFX应用程序中使用FontAwesomeFX 8.4,但每个字形都显示为一个矩形(“缺少字符”字形)。顺便说一句,这就是作者的测试应用程序的样子:

enter image description here

任何想法可能出错?

我在Arch Linux上使用Intellij IDEA。

POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.jensd.fx.glyphs</groupId>
<artifactId>testapps</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>de.jensd</groupId>
        <artifactId>fontawesomefx</artifactId>
        <version>8.4</version>
    </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:4)

这是使用FontAwesomeFX演示应用程序将Intellij Idea与Maven一起使用的分步指南。我只安装了Windows 8.1 x64,但它应该适用于每个操作系统。也许其他人试一试并添加评论。

第1步

创建一个Maven类型的新项目。如果尚未设置JDK,请选择SDK。不要选择任何原型或不选中“从原型创建”框。点击下一步。

Step1

第2步

给它一个像“com.myCompany”这样的group-id,并给它一个像“fademo”这样的工件ID,该版本不相关。点击下一步。

Step2

步骤3

为其提供项目名称和存储文件的位置。点击下一步。

Step3

步骤4

这就是新项目的样子。继续下一步。

Step4

步骤5

现在将依赖项复制到pom.xml中。如果您保存了文件,右上角会显示一个显示屏,要求您更新maven。

Step5b

只需点击“启用自动导入”即可。继续下一步。

Step5a

步骤6

现在创建一个新的Java类“App”并复制并粘贴App源的内容。之后,保存新的类。

Step6

现在,您可以通过右键单击App.java文件并选择“Run App.main()”来启动整个FontAwesomeFX演示应用程序。

Step6b

步骤7

这就是演示应用程序的外观。

Step7

源代码

pom.xml的依赖

<dependencies>
    <dependency>
        <groupId>de.jensd</groupId>
        <artifactId>fontawesomefx</artifactId>
        <version>8.4</version>
    </dependency>
</dependencies>

App.java

import de.jensd.fx.glyphs.GlyphsBuilder;
import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.GlyphsStack;
import de.jensd.fx.glyphs.GlyphsStyle;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
import de.jensd.fx.glyphs.weathericons.WeatherIcon;
import de.jensd.fx.glyphs.weathericons.WeatherIconView;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 * @author Jens Deters
 */
public class App extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        VBox root = new VBox();
        root.setSpacing(10.0);

        Button testButton = new Button();
        testButton.getStyleClass().setAll("exit-button");
        GlyphsDude.setIcon(testButton, FontAwesomeIcon.POWER_OFF, "6em");

        Button testButton2 = new Button();
        testButton2.getStyleClass().add("alien-button");
        GlyphsDude.setIcon(testButton2, WeatherIcon.ALIEN, "6em");

        FontAwesomeIconView fontAwesomeIcon
                = new FontAwesomeIconView(FontAwesomeIcon.AMBULANCE);
        fontAwesomeIcon.setStyleClass("blue-icon");
        fontAwesomeIcon.setSize("4em");

        WeatherIconView weatherIcon1 = new WeatherIconView(WeatherIcon.CLOUD);
        weatherIcon1.setStyleClass("blue-icon");
        weatherIcon1.setSize("4em");

    /*
     * .thumbs-up-icon{
     * -glyph-name: "THUMBS_UP";
     * -glyph-size: 6em;
     * }
     *
     * .thumbs-down-icon{
     * -glyph-name: "THUMBS_DOWN";
     * -glyph-size: 6em;
     * }
     */
        FontAwesomeIconView thumbsUpIcon = new FontAwesomeIconView();
        thumbsUpIcon.setStyleClass("thumbs-up-icon");

        FontAwesomeIconView thumbsDownIcon = new FontAwesomeIconView();
        thumbsDownIcon.setStyleClass("thumbs-down-icon");

        WeatherIconView weatherIcon2 = new WeatherIconView();
        weatherIcon2.setStyleClass("green-icon");
        weatherIcon2.setSize("4em");

        Text githubLabel = GlyphsDude.createIcon(FontAwesomeIcon.GITHUB);
        Text ambulanceLabel
                = GlyphsDude.createIcon(FontAwesomeIcon.PLUS_SQUARE_ALT, "60.0");
        Button starButton
                = GlyphsDude.createIconButton(FontAwesomeIcon.STAR, "Nice!", "48.0", "20.0", ContentDisplay.TOP);
        Button cloudButton
                = GlyphsDude.createIconButton(FontAwesomeIcon.CLOUD, "Download");
        ToggleButton toggleButton
                = GlyphsDude.createIconToggleButton(FontAwesomeIcon.LOCK, "Lock", "60.0", ContentDisplay.TOP);
        Region stackedIcon1
                = GlyphsStack.create().add(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.AMBULANCE).build());

        Region stackedIcon2 = GlyphsStack.create()
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.SQUARE)
                                .size("3em")
                                .styleClass("stack-base")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.STAR)
                                .size("2em")
                                .styleClass("stack-top")
                                .build()
                );

        Region stackedIcon3 = GlyphsStack.create()
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.SQUARE)
                                .style("-fx-font-size: 4em; -fx-fill: yellowgreen;")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.APPLE)
                                .style("-fx-font-size: 3em; -fx-fill: white;")
                                .build()
                );

        Region stackedIcon4 = GlyphsStack.create()
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.SQUARE)
                                .style("-fx-font-size: 4em; -fx-fill: yellowgreen;")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.APPLE)
                                .style("-fx-font-size: 3em; -fx-fill: black;")
                                .build()
                );

        Region stackedIcon5 = GlyphsStack.create()
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.BUG)
                                .style("-fx-font-size: 2em; -fx-fill: black;")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.BAN)
                                .style("-fx-font-size: 6em; -fx-fill: red; -fx-opacity: 0.5;")
                                .build()
                );

        Region stackedIcon6 = GlyphsStack.create()
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.CIRCLE)
                                .style("-fx-font-size: 10em; -fx-fill: linear-gradient(#70b4e5 0%, #247cbc 70%, #2c85c1 85%);")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.TWITTER)
                                .style("-fx-font-size: 6em; -fx-fill: white;")
                                .build()
                );

        Region stackedIcon7 = GlyphsStack.create()
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.CIRCLE)
                                .style("-fx-font-size: 10em; -fx-fill: linear-gradient(#70b4e5 0%, #247cbc 70%, #2c85c1 85%);")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.BITBUCKET)
                                .style("-fx-font-size: 6em; "
                                        + "-fx-fill: linear-gradient(#ffffff, #d2d2d2); "
                                        + "-fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.8) , 4 , 0.0 , 1 , 1 );")
                                .build()
                );
        HBox stackIconBox1 = new HBox();
        stackIconBox1.setSpacing(5.0);
        stackIconBox1.setPadding(new Insets(10.0));
        stackIconBox1.getChildren().addAll(stackedIcon1, stackedIcon2, stackedIcon3, stackedIcon4, stackedIcon5, stackedIcon6, stackedIcon7);

        Region iconStack1 = GlyphsStack.create()
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.CIRCLE)
                                .style("-fx-font-size: 12em; -fx-fill: linear-gradient(#70b4e5 0%, #247cbc 70%, #2c85c1 85%);")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.BITBUCKET)
                                .style("-fx-font-size: 6em; "
                                        + "-fx-fill: linear-gradient(#ffffff 0%, #d2d2d2); "
                                        + "-fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.8) , 4 , 0.0 , 1 , 1 );")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.BAN)
                                .style("-fx-font-size: 12em; -fx-fill: red; -fx-opacity: 0.5;")
                                .build()
                );

        Region iconStack3 = GlyphsStack.create()
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.CIRCLE)
                                .size("12em")
                                .style("-fx-fill: linear-gradient(#70b4e5 0%, #247cbc 70%, #2c85c1 85%);")
                                .build()
                )
                .add(GlyphsBuilder.create(WeatherIconView.class)
                                .glyph(WeatherIcon.RAIN)
                                .size("4em")
                                .style("-fx-fill: linear-gradient(#ffffff 0%, #d2d2d2); "
                                        + "-fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.8) , 4 , 0.0 , 1 , 1 );")
                                .build()
                )
                .add(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.BAN)
                                .size("12em")
                                .style("-fx-fill: red; -fx-opacity: 0.5;")
                                .build()
                );

        Region iconStack4 = GlyphsStack.create()
                .addAll(GlyphsBuilder.create(FontAwesomeIconView.class)
                                .glyph(FontAwesomeIcon.CIRCLE)
                                .size("12em")
                                .style("-fx-fill: linear-gradient(#70b4e5 0%, #247cbc 70%, #2c85c1 85%);")
                                .build(),
                        GlyphsBuilder.create(WeatherIconView.class)
                                .glyph(WeatherIcon.SUNRISE)
                                .size("4em")
                                .style("-fx-fill: linear-gradient(orange 0%, darkred); "
                                        + "-fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.8) , 4 , 0.0 , 1 , 1 );")
                                .build()
                );

        HBox stackIconBox2 = new HBox();
        stackIconBox2.setSpacing(5.0);
        stackIconBox2.setPadding(new Insets(10.0));
        stackIconBox2.getChildren().addAll(iconStack1, iconStack3, iconStack4);

        HBox basicIconBox = new HBox();
        basicIconBox.setAlignment(Pos.CENTER);
        basicIconBox.setSpacing(20.0);
        basicIconBox.getChildren().addAll(thumbsUpIcon, thumbsDownIcon, fontAwesomeIcon, weatherIcon1, weatherIcon2, testButton, testButton2, githubLabel, ambulanceLabel);

        root.getChildren().addAll(createMenubar(), basicIconBox, starButton, cloudButton, toggleButton, stackIconBox1, stackIconBox2);

        Scene scene = new Scene(root);
        scene.getStylesheets().addAll(GlyphsStyle.DEFAULT.getStylePath());

        primaryStage.setScene(scene);
        primaryStage.setTitle("FontAwesomeFX demo");
        primaryStage.show();

    }

    private MenuBar createMenubar() {

        MenuBar menuBar = new MenuBar();

        MenuItem openItem = new MenuItem("Open");
        GlyphsDude.setIcon(openItem, FontAwesomeIcon.FILE);
        MenuItem saveItem = new MenuItem("Save");
        GlyphsDude.setIcon(saveItem, FontAwesomeIcon.DOWNLOAD);
        MenuItem saveAsItem = new MenuItem("Save As...");
        GlyphsDude.setIcon(saveAsItem, FontAwesomeIcon.DOWNLOAD);
        MenuItem exitItem = new MenuItem("Exit");
        GlyphsDude.setIcon(exitItem, FontAwesomeIcon.SIGN_OUT);

        Menu menuFile = new Menu("File");
        menuFile.getItems().add(openItem);
        menuFile.getItems().add(saveItem);
        menuFile.getItems().add(saveAsItem);
        menuFile.getItems().add(new SeparatorMenuItem());
        menuFile.getItems().add(exitItem);

        Menu menuEdit = new Menu("Edit");
        Menu menuView = new Menu("View");

        menuBar.getMenus().addAll(menuFile, menuEdit, menuView);

        return menuBar;
    }

    public static void main(String[] args) {
        System.setProperty("prism.lcdtext", "false");
        launch(args);
    }
}

更新

在安装了Oracle JDK 1.8.0_45的Ubuntu 15.04 x64中完成相同的操作并且它可以工作:

Ubuntu