views:

26

answers:

1

Is there a way to make the text in a JTextPane look similar to that of console output? By that I mean, basically, how each character is the same width, so that things like ASCII art, or spacing indentation would work correctly.

For example, currently, 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 in the same position, so if there was text following those spaces, the text would not be aligned.

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

+1  A: 

set the font to a fixed width font such as courier, or use the Monospaced font-family.

JTextPane text = new JTextPane();
Font font = new Font("Monospaced", Font.PLAIN, 14);
text.setFont(font);
pstanton
Thank you! That works great.
404 Not Found