Underlined JLabel

后端 未结 2 1105
忘掉有多难
忘掉有多难 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("YOUR TEXT HERE");
    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));
    

提交回复
热议问题