我尝试使用Java显示表情符号。我发现了https://github.com/vdurmont/emoji-java这个库,它非常有用,但只能在终端中工作。
我尝试使用swing显示标签。
我该如何在Java的swing中显示带有表情符号的标签?
package Graphic;
import com.vdurmont.emoji.EmojiParser;
import javax.swing.*;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class Graphic{
public static void Graphic() {
JFrame frame = new JFrame();
frame.setSize(400, 400); // Tamaño de la ventana principal
frame.setTitle("Orders work");
String withlove = "With :heart: Nicoll";
String result = EmojiParser.parseToUnicode(withlove);
System.out.println(result);
JLabel conamor = new JLabel(result);
conamor.setText(result);
frame.add(conamor);
frame.setVisible(true);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
EmojiParser
是做什么的,但如果我将代码改为String result = "With \u2764 Nicoll";
,在运行Windows 10和Java 15时会得到一个心形符号。请参见图片。--- 可能是使用了不支持表情符号的字体。 - undefinedyourLabel.setFont(new Font("SansSerif", Font.PLAIN, fontSize));
。 - undefined