在OS X上的JLabel中显示unicode字符

时间:2017-10-26 12:51:32

标签: java swing unicode

对于JabRef,我们有一个LaTeX到Unicode转换器来显示例如标题中的斜体字体。但是,在我的Mac上,尽管我在调试器(issue on GitHub)中看到了正确的Unicode字符串,但这并未正确呈现。我使用创建的Unicode字符串附加了一个最小的示例。我在我的机器上看到的内容(MacOS Sierra 10.12.6,Java 1.8.0_144)如下

img

,而IDEA中的调试器正确显示

img2

是否有人可以分享一些如何解决这个问题的见解?我阅读了几篇SO帖子,建议使用支持此字体或以某种方式设置字体大小的字体。但是,我不是在这里调整任何一个。为什么在默认设置中失败?

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

public class SwingJLabelTester extends JPanel{

    private SwingJLabelTester() {
        super(new GridLayout(1,1));
//        final String latexString = LatexToUnicodeAdapter.format("This is a \\textit{test for italics} and \\textbf{a test for bold}");
        final String latexString = "This is a \uD835\uDC61\uD835\uDC52\uD835\uDC60\uD835\uDC61 \uD835\uDC53\uD835\uDC5C\uD835\uDC5F \uD835\uDC56\uD835\uDC61\uD835\uDC4E\uD835\uDC59\uD835\uDC56\uD835\uDC50\uD835\uDC60 and \uD835\uDC1A \uD835\uDC2D\uD835\uDC1E\uD835\uDC2C\uD835\uDC2D \uD835\uDC1F\uD835\uDC28\uD835\uDC2B \uD835\uDC1B\uD835\uDC28\uD835\uDC25\uD835\uDC1D";
        final JLabel label = new JLabel(latexString, SwingConstants.CENTER);
        label.setVerticalTextPosition(SwingConstants.BOTTOM);
        label.setHorizontalTextPosition(SwingConstants.CENTER);
        add(label);
    }

    private static void createAndShowGUI() {
        final JFrame frame = new JFrame("LabelDemo");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(new SwingJLabelTester());
        frame.setSize(400,400);
        frame.setVisible(true);
    }

    public static void main(final String[] args) {
        SwingUtilities.invokeLater(SwingJLabelTester::createAndShowGUI);
    }

}

0 个答案:

没有答案