我需要为我的一个 JButton 中的超链接制作字体下划线和蓝色,但似乎字体类没有明显的方法来执行此操作。我不能使用 attributetext,因为我不会用 Graphics 类来显示它。无论如何我可以做到这一点吗?我只需要 JButton 的标题为蓝色并带有下划线。
最佳答案
我来不及回复了。但无论如何,我要把它发布在这里。也许这会对某人有帮助。
JButton button = new JButton("Label");
HashMap<TextAttribute, Object> textAttrMap = new HashMap<TextAttribute, Object>();
textAttrMap.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
textAttrMap.put(TextAttribute.FOREGROUND, Color.BLUE);
button.setFont(button.getFont().deriveFont(textAttrMap));
引用号:http://docs.oracle.com/javase/tutorial/2d/text/examples/AttributedText.java
关于java - 更改字体颜色并使其带有下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1242289/