更改 Font Awesome Glyph 的颜色
Change color of FontAwsome Glyph
我在按钮中使用 FontAwesome Glyphs 并想在方法中更改颜色。有谁知道如何做到这一点?我还尝试了“-fx-fill: black;”。两个都不行。
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
public FontAwesomeIcon close;
close.setStyle("-fx-fill: black;");
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
VBox vBox = new VBox();
FontAwesomeIconView closeIcon = new FontAwesomeIconView();
closeIcon.setStyle("-glyph-name: CLOSE;");
Button button = new Button("change icon color to red");
button.setOnAction(event -> closeIcon.setStyle("-glyph-name: CLOSE; -fx-fill: red;"));
vBox.getChildren().addAll(closeIcon, button);
stage.setScene(new Scene(vBox));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
试试这个
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
FontAwesomeIconView fa = new FontAwesomeIconView(FontAwesomeIcon.CLOSE);
fa.setStyle("-fx-font-family: FontAwesome; -fx-fill: BLACK; -fx-font-size: 28px");
FontAwesomeIconView fontAwesomeIconView = new FontAwesomeIconView(FontAwesomeIcon.CLOSE);
fontAwesomeIconView.setFill(Color.rgb(66, 139, 202));
对于无法本地设置的属性,您应该使用 setStyle
。
还有尺码:
fontAwesomeIconView.setGlyphSize(Font.getDefault().getSize() * 2);
我在按钮中使用 FontAwesome Glyphs 并想在方法中更改颜色。有谁知道如何做到这一点?我还尝试了“-fx-fill: black;”。两个都不行。
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
public FontAwesomeIcon close;
close.setStyle("-fx-fill: black;");
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
VBox vBox = new VBox();
FontAwesomeIconView closeIcon = new FontAwesomeIconView();
closeIcon.setStyle("-glyph-name: CLOSE;");
Button button = new Button("change icon color to red");
button.setOnAction(event -> closeIcon.setStyle("-glyph-name: CLOSE; -fx-fill: red;"));
vBox.getChildren().addAll(closeIcon, button);
stage.setScene(new Scene(vBox));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
试试这个
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
FontAwesomeIconView fa = new FontAwesomeIconView(FontAwesomeIcon.CLOSE);
fa.setStyle("-fx-font-family: FontAwesome; -fx-fill: BLACK; -fx-font-size: 28px");
FontAwesomeIconView fontAwesomeIconView = new FontAwesomeIconView(FontAwesomeIcon.CLOSE);
fontAwesomeIconView.setFill(Color.rgb(66, 139, 202));
对于无法本地设置的属性,您应该使用 setStyle
。
还有尺码:
fontAwesomeIconView.setGlyphSize(Font.getDefault().getSize() * 2);