0

我需要在我的一个 JButtons 中为超链接添加字体下划线和蓝色,但似乎字体类没有明显的方法可以做到这一点。我不能使用属性文本,因为我不会用 Graphics 类显示它。无论如何我可以做到这一点吗?我只需要我的 JButton 的标题为蓝色并带有下划线。

4

3 回答 3

3

我来不及回复了。但无论如何,我要把它贴在这里。也许它会对某人有所帮助。

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

于 2013-08-01T19:06:00.273 回答
0
JButton button = new JButton("OK");
button.setBackground(Color.blue);

Font buttonFont=new Font(button.getFont().getName(),Font.UNDERLINED+Font.BOLD,button.getFont().getSize());  
button.setFont(buttonFont);  
于 2009-08-07T00:41:06.090 回答
0

我最终解决了无法通过用.....标签包围我的字符串来为文本添加下划线的问题。

于 2009-09-11T19:43:50.330 回答