How do I set the number of columns for JTextPane

I only found a method setSize() of JTextPane class. How can I set the number of columns in a JTextPane? Each column can be written one letter.

Thanks.

[163 byte] By [youhaodiyia] at [2007-11-27 11:09:00]
# 1

You can't. You can try using a JTextArea.

camickra at 2007-7-29 13:32:39 > top of Java-index,Desktop,Core GUI APIs...
# 2

JTextArea can't meet my requirement. If I set the size of a JTextPane, the number of columns will be different between Windows and Linux. For example, if the JTextPane contains 70 letters per line in linux, it will contains more than 70 letters in Windows XP. How can I make them same?

Thanks.

youhaodiyia at 2007-7-29 13:32:39 > top of Java-index,Desktop,Core GUI APIs...
# 3

The only thing I can think of is to set the font to mono, then use FontMetrics to figure out how wide a single character is, then set the width of the pane.

mbmerrilla at 2007-7-29 13:32:39 > top of Java-index,Desktop,Core GUI APIs...
# 4

How does FontMetrics change the wide of a single character? I only found there are many get*** methods in this class and no set*** method.

youhaodiyia at 2007-7-29 13:32:39 > top of Java-index,Desktop,Core GUI APIs...
# 5

You're not going to use FontMetrics to change the width of the characters; you're going to use it figure out how wide a single character is. Then multiply by the number of characters you want to have in a line, and presto! You know how wide to make your JTextPane.

Unless I've misunderstood your problem, of course.

mbmerrilla at 2007-7-29 13:32:39 > top of Java-index,Desktop,Core GUI APIs...