JTextPane style for console formatting?

Is there a way to make text in JTextPane look like a console? By this I mean basically how each character has the same width, so things like ASCII art or spacing indentation will work correctly.

For example, at present, if I type “First,” and then 5 spaces, and then on a new line, “Second,” and then 4 spaces, the two lines do not end at the same position, so if there is text, the following these spaces, the text will not be aligned.

I don't know if it will change anything, but JComponents will also be included in JTextPane.

+3
source share
1 answer

Install the font with a fixed-width font, such as a courier, or use the font family Monospaced.

JTextPane text = new JTextPane();
Font font = new Font(Font.MONOSPACED, Font.PLAIN, 14);
text.setFont(font);
+5
source

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


All Articles