Skip to main content

Monospaced font problems

No replies
ExorcismTongs
Offline
Joined: 2006-02-17

I am having problems with the monospaced font in Swing. It appears that the "O" (capital letter o) character has somehow been switched with the "0" (zero) character, because the letter shows up as the number and vice versa. The problem only happens with the "Monospaced" and "DialogInput" fonts, as well as the "Lucida Typewriter" font that those two fonts are mapped to. All other fonts show up fine. However, when I use Lucida Typewriter in another program, like konsole or kwrite, the characters show up correctly.

Sample code:

<br />
import java.awt.*;<br />
import javax.swing.*;</p>
<p>public class Monospaced extends javax.swing.JDialog {<br />
    public Monospaced(java.awt.Frame parent, boolean modal) {<br />
        JTextArea textArea = new JTextArea();<br />
        textArea.setFont(new Font("Monospaced", Font.PLAIN, 12));<br />
        textArea.setText("This is a zero: 0\n" +<br />
                         "This is a capital letter o: O");<br />
        getContentPane().add(textArea, java.awt.BorderLayout.CENTER);<br />
    }</p>
<p>    public static void main(String args[]) {<br />
        new Monospaced(new javax.swing.JFrame(), true).show();<br />
    }<br />
}<br />

And the program produces the following results: http://home.comcast.net/~exorcismtongs/zero.jpg

I am having this problem on a computer running Red Hat Linux 9 w/KDE. It happens in both JRE 1.4.2_03 and JRE 1.5.0. Is there a way I can fix this?