我正在尝试改变我的工具提示的大小。
我使用的是:
UIManager.put("ToolTip.font", new Font("SansSerif",Font.PLAIN,25));这在一般情况下工作得很好。但在我的例子中,我使用的是Nimbus LaF,代码如下:
UIManager.LookAndFeelInfo plafinfo[] = UIManager.getInstalledLookAndFeels();
boolean LaFfound=false;
int LaFindex=0;
for (int look = 0; look < plafinfo.length && !LaFfound; look++)
{
if(plafinfo[look].getClassName().toLowerCase().contains("nimbus"))
{
LaFfound=true;
LaFindex=look;
}
}
try {
if(LaFfound) {
UIManager.setLookAndFeel(plafinfo[LaFindex].getClassName());
}
else {UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());}
}
catch(Exception e){Logger.getLogger(Fenetre.class.getName()).log(Level.SEVERE, null, e);}
//correct tooltips size
UIManager.put("ToolTip.font", new Font("SansSerif",Font.PLAIN,25));在这种情况下,UIManager似乎完全忽略了我的指令,就好像"ToolTip.font“不是Nimbus LaF中被承认的属性……
但是根据这个页面:http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html这个属性是存在的。
我的代码出了什么问题?或者我如何用其他方法解决这个问题?
非常感谢!
发布于 2013-05-21 10:00:26
Nimbus似乎与其他LAF的工作方式不同。您需要在设置LAF之前设置该属性:
UIManager.put("ToolTip.font", new Font("SansSerif",Font.PLAIN,25));
try
{
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
}
catch (Exception e)
{
// If Nimbus is not available, you can set the GUI to another look and feel.
}对于其他LAF,我相信您可以在创建该类型的第一个组件之前更改任何属性。
https://stackoverflow.com/questions/16660626
复制相似问题