相关疑难解决方法(0)

JTextPane/JTextField奇怪的行为与稀有字符

我在JTextPane/JTextField中发现了一个奇怪的错误(或者在它们下面的字体渲染中的某个地方).我想知道是否有其他人遇到过这种情况并且可能有解决方案.

我试图在JTextPane中显示一些"特殊"或罕见的字符,并且一旦我更改了JTextField的字体(与JTextPane完全无关!),JTextPane就会"分解",并且不再显示这些字符字符.

这应该更好地解释我的意思:

public class Scrap {

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 200);
    frame.setLayout(new BorderLayout());

    JTextField field = new JTextField();

    // Uncomment this line... and the JTextPane nor the JTextField
    // no longer display the characters
    // field.setFont(new Font("Arial", Font.PLAIN, 14));

    frame.add(field, BorderLayout.SOUTH);

    JTextPane textPane = new JTextPane();
    textPane.setFont(new Font("Arial", Font.PLAIN, 14));

    JScrollPane scroll = new JScrollPane(textPane);
    frame.add(scroll, BorderLayout.CENTER);

    StyledDocument doc = (StyledDocument) textPane.getDocument();

    try {
        String str = "? ?? ?"; …
Run Code Online (Sandbox Code Playgroud)

java swing jtextpane jtextfield

5
推荐指数
1
解决办法
2443
查看次数

标签 统计

java ×1

jtextfield ×1

jtextpane ×1

swing ×1