Any descendant or JTextField replacement that spans more Chinese characters?

I am working on an application that uses a JTextfield object as a text input component. During some tests, I saw that not all Chinese characters can be displayed using this component. At first, this seems normal: some Chinese characters are so big that they are not even covered by Unicode, which (in my humble opinion) explain why they cannot be copied to the clipboard (only as a bitmap, which means that font modifications can't be tested).

However, there also seem to be characters, such as the four dragon characters (explained in URL The largest Chinese character in Unicode ), which may be copied to the clipboard, but which does not seem to be accepted by the JTextField object.

Therefore, my question is: is there any descendant of JTextField that spans all Chinese characters, or at least those that are present in Unicode? Or does anyone know of another, more powerful component?

Thanks in advance

+4
source share
2 answers

With JTextFieldyou will need to specify a font that can support all the characters that you want to use.

, . , MingLiU-ExtB , 𪚥, , 漢字.

Arial Unicode MS MingLiU , .

, JTextField.

JTextPane , , Windows. , , . ( , . Windows, Java: . Font Fallback .)

JTextField JTextPane .

public class ChineseFont {

  public static void main(String[] args) {
    SwingUtilities.invokeLater(() -> {
      String text = "test 𪚥 test 漢字.";

      JTextField textField1 = new JTextField(text);
      textField1.setFont(new Font("Arial Unicode MS", Font.PLAIN, 24));
      JLabel label1 = new JLabel("JTextField " + textField1.getFont().getFontName());

      JTextField textField2 = new JTextField(text);
      textField2.setFont(new Font("MingLiU", Font.PLAIN, 24));
      JLabel label2 = new JLabel("JTextField " + textField2.getFont().getFontName());

      JTextField textField3 = new JTextField(text);
      textField3.setFont(new Font("MingLiU-ExtB", Font.PLAIN, 24));
      JLabel label3 = new JLabel("JTextField " + textField3.getFont().getFontName());

      JTextPane  textPane4 = new JTextPane();
      textPane4.setFont(new Font("Arial Unicode MS", Font.PLAIN, 24));
      textPane4.setText(text);
      JLabel label4 = new JLabel("JTextPane " + textPane4.getFont().getName());

      JTextPane  textPane5 = new JTextPane();
      textPane5.setFont(new Font("MingLiU", Font.PLAIN, 24));
      textPane5.setText(text);
      JLabel label5 = new JLabel("JTextPane " + textPane5.getFont().getName());

      JFrame frame = new JFrame();
      Container contentPane = frame.getContentPane();
      contentPane.setLayout(new GridLayout(5, 2, 2, 6));
      contentPane.add(label1);
      contentPane.add(textField1);
      contentPane.add(label2);
      contentPane.add(textField2);
      contentPane.add(label3);
      contentPane.add(textField3);
      contentPane.add(label4);
      contentPane.add(textPane4);
      contentPane.add(label5);
      contentPane.add(textPane5);

      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setVisible(true);
    });
  }
}

, AttributedText. .

+1

@Enwired, , . - , , . , , , . . , .

0

Source: https://habr.com/ru/post/1662112/


All Articles