A question about the Font in JTextPane

I added a JTextPane in a frame. When input letters in the text pane, the width of them is different. For example, a "H" is wider than "i". How can I make them have same width?

package test;

import java.awt.Color;

import javax.swing.JFrame;

import javax.swing.JTextPane;

import javax.swing.text.AttributeSet;

import javax.swing.text.BadLocationException;

import javax.swing.text.SimpleAttributeSet;

import javax.swing.text.StyleConstants;

publicclass TestFont{

/**

* @param args

*/

publicstaticvoid main(String[] args){

// TODO Auto-generated method stub

JFrame frame =new JFrame();

JTextPane textPane =new JTextPane();

AttributeSet as1 =new SimpleAttributeSet();

try{

textPane.getDocument().insertString(0,"abcabc",as1);

textPane.getDocument().insertString(textPane.getDocument().getLength(),"\nEEE", as1);

frame.add(textPane);

frame.setSize(100,100);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}catch(BadLocationException ex){

ex.printStackTrace();

}

}

}

[2128 byte] By [youhaodiyia] at [2007-11-27 11:01:09]
# 1

Use a monospaced font:

textPane.setFont( new Font("monospaced", Font.PLAIN, 12) );

camickra at 2007-7-29 12:34:43 > top of Java-index,Desktop,Core GUI APIs...