Underlined JLabel

后端 未结 2 1110
忘掉有多难
忘掉有多难 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:47

    JLabel label = new JLabel("Underlined Label");
    Font font = label.getFont();
    Map attributes = new HashMap<>(font.getAttributes());
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    label.setFont(font.deriveFont(attributes));
    

提交回复
热议问题