0

I am developping a text editor with Java swing, I want to use a monospace font to display (for example Consolas font):

JTextArea textArea = new JTextArea("text");
textArea.setFont(new Font("Consolas", Font.PLAIN, 12));

But if there's any unicode character(for ex: Japanese character), it shows square (this font does not support this kind of character).

I still want to use Consolas, but if there's any character which is not supported, it will use other font to render (a unicode font). How can I do that?

I think about use html to set font for each character but maybe it's too heavy. I just want 2 font: 1 monospace font & 1 unicode font

Bentaye
  • 9,403
  • 5
  • 32
  • 45
yelliver
  • 5,648
  • 5
  • 34
  • 65
  • I would first try to find a Monospace font that supports unicode better. Maybe this: https://stackoverflow.com/questions/1938639/monospace-unicode-font?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – user3237736 Apr 16 '18 at 19:19
  • @user3237736 I am thinking about create my own font by importing from other font, but maybe a programming solution is my expectation – yelliver Apr 16 '18 at 19:23
  • @yelliver [1] My answer to an unrelated question on Japanese fonts [_"String.format for double-width characters"_](https://stackoverflow.com/a/53934253/2985643) might be helpful, though it wasn't about Swing. [2] As mentioned in that answer, try [Google's web site for fonts](https://fonts.google.com/) to search for monospaced Japanese fonts. [3] Have you tried using the **Monospaced** font instead of **Consolas**? I think it should render all Japanese characters. [4] If you find a monospace font that supports all Japanese characters, would you still need a "backup" Unicode font as well? – skomisa Jan 04 '19 at 06:40

0 Answers0