开发者

How come JLabel doesn't show underscore character?

For some reason JLabel doesn't show underscore sym开发者_如何学运维bol. Is there anything in particular I have to do for enabling such behavior?

Doesn't work in Windows, Linux, MacOS with Java 1.6.x


This is the code I used to see if this worked. Try running this on your machine.

import java.awt.*;
import javax.swing.*;

public class TestUnderscore 
{
  // Test routine.
  public static void main(String[] args) 
  {
    JFrame frame = new JFrame();
    frame.getContentPane().setBackground(Color.yellow);
    frame.getContentPane().add(new JLabel("Test_Underscore$$"));
    frame.getContentPane().setLayout(new FlowLayout());
    frame.setSize(450, 450);
    frame.setVisible(true);
  }
}


Does not work for me on Linux. Same issue for highlighted text in JTextArea. If line1 and line 2 contain underscores and both are highlighted, underscores in line 1 are not visible but underscores in line2 are. Changing alpha values of highlight color did not fix problem.

Found a fix - change the font. Both worked when I used Verdana 12pt.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜