我想知道如何将网页图标字体(来自Google Material Design Icons)作为字体加载到我的JavaFx应用程序中,而不是使用图标本身。这个是可能的吗?我知道这可以在CSS中完成,但不确定它在JavaFX-CSS中是否有效。我尝试使用@font-font并在css中指定URL,但得到了com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged和Could not load @font-face font [https://fonts.googleapis.com/icon?family=Material+Icons]
请让我知道这是否可以做到,谢谢!
这是我的StyleSheet:
@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类:
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();
}
}发布于 2016-02-12 04:49:39
你可以使用这个库FontAwesomeFx。我一直在一个项目中使用它,因为FontAwesome,但它也包含谷歌材料,设计图标和其他一些。
发布于 2016-02-18 02:20:19
在http://jiconfont.github.io/上试用jIconFont
示例:
IconNode iconNode = new IconNode(GoogleMaterialDesignIcons.ADD);
iconNode.setIconSize(15);
iconNode.setFill(Color.BLACK);
Button button = new Button("Save");
button.setGraphic(iconNode);发布于 2018-06-19 17:00:30
今天早上我也遇到了同样的问题。我的问题是我公司的代理设置。也许对你来说也是一样。
您可以通过以下方法解决此问题:
System.setProperty("http.proxyHost", "yourproxyhere");
System.setProperty("http.proxyPort", "yourporthere");希望这对下一篇文章有所帮助:)
https://stackoverflow.com/questions/35349504
复制相似问题