首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在JavaFX中使用网页字体

在JavaFX中使用网页字体
EN

Stack Overflow用户
提问于 2016-02-12 04:34:59
回答 3查看 2.8K关注 0票数 3

我想知道如何将网页图标字体(来自Google Material Design Icons)作为字体加载到我的JavaFx应用程序中,而不是使用图标本身。这个是可能的吗?我知道这可以在CSS中完成,但不确定它在JavaFX-CSS中是否有效。我尝试使用@font-font并在css中指定URL,但得到了com.sun.javafx.css.StyleManager loadStylesheetUnPrivilegedCould not load @font-face font [https://fonts.googleapis.com/icon?family=Material+Icons]

请让我知道这是否可以做到,谢谢!

这是我的StyleSheet:

代码语言:javascript
复制
@font-face {
    src: url('https://fonts.googleapis.com/icon?family=Material+Icons');
}

.button {
    -fx-background-color: transparent;
    -fx-background-radius: 0;
    -fx-border-style: none;
    -fx-text-fill: white;
    -fx-font-family: 'Material Icons';
    -fx-font: 20;

}

Java类:

代码语言:javascript
复制
import javafx.application.Application;
import javafx.beans.binding.StringBinding;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * Created by digitalblueeye on 2/11/16.
 */
public class Revamp extends Application {
    public static void main(String args[]) {
        launch(args);
    }
    @Override
    public void start(Stage stage) throws Exception {

        BorderPane root = new BorderPane();
        root.setId("root");
        Scene scene = new Scene(root,1000,800);
        scene.getStylesheets().add("Assets/StyleSheets/Styles.css");

        HBox ProjectBar = new HBox();
        ProjectBar.setId("project-bar");
        Button MenuButton = new Button("Menu");
        Label ProjectName = new Label("My Project");
        Label SaveStatus = new Label("All changes saved.");
        ComboBox<?> LaunchButton = new ComboBox<>();

        ProjectBar.getChildren().addAll(MenuButton,ProjectName,SaveStatus,LaunchButton);

        TabPane tabhome = new TabPane();
        tabhome.setId("tab-home");
        Tab welcomeTab = new Tab("Startup");
        tabhome.getTabs().add(welcomeTab);

        BorderPane content = new BorderPane();
        HBox toolBar = new HBox();
        toolBar.setId("tool-bar");
        ChoiceBox toolSelector = new ChoiceBox();
        ChoiceBox textElements = new ChoiceBox();
        ChoiceBox layoutElements = new ChoiceBox();
        ChoiceBox InteractiveElements = new ChoiceBox();
        ChoiceBox mediaElements = new ChoiceBox();
        ComboBox viewPercent = new ComboBox();
        Button zoomplus = new Button("zoom_in");
        Button zoomminus = new Button("zoom_out");
        toolBar.getChildren().addAll(toolSelector,textElements,layoutElements,
                                        InteractiveElements,mediaElements,viewPercent,
                                        zoomplus,zoomminus);
        content.setTop(toolBar);
        welcomeTab.setContent(content);



        VBox header = new VBox();
        header.getChildren().addAll(ProjectBar,tabhome);





        root.setTop(header);

        stage.setScene(scene);
        stage.show();
    }
}
EN

回答 3

Stack Overflow用户

发布于 2016-02-12 04:49:39

你可以使用这个库FontAwesomeFx。我一直在一个项目中使用它,因为FontAwesome,但它也包含谷歌材料,设计图标和其他一些。

票数 0
EN

Stack Overflow用户

发布于 2016-02-18 02:20:19

http://jiconfont.github.io/上试用jIconFont

示例:

代码语言:javascript
复制
IconNode iconNode = new IconNode(GoogleMaterialDesignIcons.ADD);

iconNode.setIconSize(15);

iconNode.setFill(Color.BLACK);

Button button = new Button("Save");

button.setGraphic(iconNode);
票数 0
EN

Stack Overflow用户

发布于 2018-06-19 17:00:30

今天早上我也遇到了同样的问题。我的问题是我公司的代理设置。也许对你来说也是一样。

您可以通过以下方法解决此问题:

代码语言:javascript
复制
System.setProperty("http.proxyHost", "yourproxyhere");
System.setProperty("http.proxyPort", "yourporthere");

希望这对下一篇文章有所帮助:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35349504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档