如何在OS X上的JavaFX中显示表情符号? [英] How do I display emoji in JavaFX on OS X?

查看:741
本文介绍了如何在OS X上的JavaFX中显示表情符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在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:

  • Symbola is a serif font and doesn't fit the aesthetic of my application
  • The user should eventually be able to choose their own font

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:

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();
    }
}

The above was adapted from a JavaFX tutorial

As you can see, black bars are displayed instead of

这篇关于如何在OS X上的JavaFX中显示表情符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆