简体   繁体   中英

How come JLabel doesn't show underscore character?

For some reason JLabel doesn't show underscore symbol. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM