Hi everybody,
I'm having a bit of a strange problem with a JTextArea--I'm setting the font to one that's fixed width (Courier), but my text doesn't always line up. The spacing is off sometimes. Would anyone please help me figure out why this is?
Here's a test program that demonstrates this problem:
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class FontTest {
public static void main( String[] args ) {
try {
JFrame frame = new JFrame();
frame.setSize( 300, 300 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
JTextArea area = new JTextArea();
area.setFont( new Font( "Monospaced", Font.PLAIN, 14 ) );
frame.add( new JScrollPane( area ) );
frame.setVisible( true );
} catch( Exception e ) {
e.printStackTrace();
System.exit( -1 );
}
}
}
To reproduce it, type 12345<space>67890, then on the next line type "5" eleven times. The 0 should line up with the last five, but it doesn't; the 5 sticks out a little farther than the 0.
This might be an operating system problem also; I don't know, though. If it would be helpful, I'm using Linux (Fedora) and JDK 1.6 update 10.
EDIT: I changed "Courier" to "Monospaced" so I could use a default Java font without worrying whether a computer has Courier, but still no luck on getting characters to line up.
Thanks,
Jezzica85
Edited by: jezzica85 on Dec 16, 2008 8:34 AM