开发者

Style a JTextPane to have console-like formatting?

Is there a way to make the text in a JTextPane look similar to that of console output? By th开发者_JAVA百科at 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.


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(Font.MONOSPACED, Font.PLAIN, 14);
text.setFont(font);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜