0

If I have a JLabel with <u> tag, such as <html><u>text</u>, with WindowsLookAndFeel and WindowsClassicLookAndFeel the underline is not rendered. I have reported this bug.

If no Look and Feel is set, or with Nimbus, all correct.

I know I can set the font attributes of the JLabel, but what if I only want to render one part of the text?

EDIT: I have tested and found that it is a bug of MigLayout combined with UIManger font setting.

Try the code: comment out anyone of UIManager.put("Label.font") or setLayout(MigLayout(xxx)) will solve the problem, but if they are both present, the line is not shown. I changed the title of question to describe it better. Now I see it has nothing to do with L&F, because Nimbus neither render the line.

The effect is:

enter image description here

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

import net.miginfocom.swing.MigLayout;

public class WindowsLFUnderline extends JDialog {
    public WindowsLFUnderline() {
        begin();
    }

    private void begin() {

        try {
            UIManager.setLookAndFeel(new WindowsClassicLookAndFeel());
            //UIManager.setLookAndFeel(new WindowsLookAndFeel());
            UIManager.put("Label.font", new Font("SimSun", Font.PLAIN, 13));
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLayout(new BorderLayout());
        JTabbedPane tabs = new JTabbedPane();
        JLayeredPane layer = new JLayeredPane();

        layer.setLayout(new MigLayout("insets 5, fill", "[]", "[]"));
//        layer.setLayout(new BorderLayout());
        JLabel test = new JLabel("<html><u>TEST</u>");
        test.setForeground(Color.BLUE);
        test.setBounds(0, 0, 300, 150);
        layer.add(test, BorderLayout.CENTER);

        tabs.addTab("tab1", layer);

        add(tabs, BorderLayout.CENTER);
        pack();

        setVisible(true);
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                WindowsLFUnderline frame = new WindowsLFUnderline();

            }

        });
    }
}
WesternGun
  • 11,303
  • 6
  • 88
  • 157

0 Answers0