如何在OS X上的JavaFX中显示表情符号? [英] How do I display emoji in JavaFX on OS X?
问题描述
我无法在Mac OS X的JavaFX应用程序中显示表情符号。在Linux上,只要系统上有表情符号字体(Symbola,Noto Emoji),字体替换就会启动。
然而在OS X上没有这样的运气。我曾尝试添加
正如您所看到的,显示黑条而不是 I'm having trouble getting emoji to display in my JavaFX application on Mac OS X. On Linux, as long as I have an emoji font (Symbola, Noto Emoji) on the system, font substitution will kick in. On OS X, however, no such luck. I have tried adding the Symbola font as a resource, and that only works if I change the label's font to Symbola. I would prefer not to do this because: Apple has the "Apple Color Emoji" font. If I set my label that font, emoji will display but text-spacing is erratic. Here's a sample application to see the issue: The above was adapted from a JavaFX tutorial As you can see, black bars are displayed instead of
这篇关于如何在OS X上的JavaFX中显示表情符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 300, 130, Color.WHITE);
GridPane gridpane = new GridPane();
gridpane.setPadding(new Insets(5));
// Add cat emoji
Label label = new Label("\uD83D\uDC31");
GridPane.setHalignment(label, HPos.CENTER);
gridpane.add(label, 0, 0);
root.getChildren().add(gridpane);
primaryStage.setScene(scene);
primaryStage.show();
}
}