Underlined JLabel

后端 未结 2 1104
忘掉有多难
忘掉有多难 2020-12-10 00:50

I am trying to make a JLabel underlined. I searched everywhere, but I got nothing. Even in the properties, there is no option for underlining the JLabel. What can I do?

相关标签:
2条回答
  • 2020-12-10 01:42
    JLabel label = new JLabel("<HTML><U>YOUR TEXT HERE</U></HTML>");
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    

    OR

    JLabel label = new JLabel("Underlined Label");
    Font font = label.getFont();
    Map attributes = font.getAttributes();
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    label.setFont(font.deriveFont(attributes));
    
    0 讨论(0)
  • 2020-12-10 01:47
    JLabel label = new JLabel("Underlined Label");
    Font font = label.getFont();
    Map<TextAttribute, Object> attributes = new HashMap<>(font.getAttributes());
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    label.setFont(font.deriveFont(attributes));
    
    0 讨论(0)
提交回复
热议问题