由于默认的LookAndFeel字体太小,所以我使用了几行代码将其设置为Nimbus,而我的JOptionPane显示了大小不同的Yes和No按钮。是的仍然很小,而No被设置为与我指定的大小相同。有人知道为什么或如何修复它吗?
public static void setUIFont(Font a){
FontUIResource ax=new FontUIResource(a);
javax.swing.UIManager.put("OptionPane.messageFont", ax);
javax.swing.UIManager.put("OptionPane.buttonFont", ax);
javax.swing.UIManager.put("OptionPane.Font", ax);
javax.swing.UIManager.put("InternalFrame.titleFont", ax);
javax.swing.UIManager.put("TextField.font", ax);
javax.swing.UIManager.put("ComboBox.font", ax);
}
..。
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
class UseNimBus extends SwingInvoker{
public void run(){
JDialog.setDefaultLookAndFeelDecorated(true);
setUIFont(new FontUIResource(new Font(ufont, Font.PLAIN, 20)));
}
}
(new UseNimBus()).execute();// just invokeLater()
下面的行显示选项窗格,但它有大小不同的Yes和No。这是正常的还是只是我的问题?
inputValuex=JOptionPane.showConfirmDialog(
myWin, "Are you exiting?", "You clicked X", JOptionPane.YES_NO_OPTION);
更新
还是不起作用。我试过用密码
javax.swing.UIManager.put("OptionPane.isYesLast", true);
更改“是”按钮的位置,但没有任何效果。我只是想看看如何设置这些值,比如boolean。
此外,我甚至在UIManager.getDefaults()
中列出了包含选项窗格或按钮的所有键,它们的字体大小都设置为20。是按钮仍然是较小的字体。
发布于 2013-03-19 02:30:26
JButton
的字体实际上来自Button.font
属性。
如果我将这个添加到您的属性列表中,它就会工作。
javax.swing.UIManager.put("Button.font", ax);
为什么你有两个不同的尺寸,虽然有趣,但在这个时刻我无法理解。
发布于 2013-03-20 11:12:38
看起来,在optionPane中创建的第一个按钮没有使用自定义字体的原因是,它是rootPane的defaultButton。既然如此,它有一个特殊的默认状态,用于查找属性-如果按钮的设置字体为UIResource类型。
所以发生的是
由于一些我不知道的原因(但请记住,Nimbus中命名/子组件的查找失败了),下面的设置没有任何效果。
UIManager.put("\"OptionPane.button\"[Default].font", ax);
UIManager.put("OptionPane:\"OptionPane.button\"[Default].font", ax);
此外,当将第二个按钮设置为UIResource时,第二个按钮的自定义字体在滚动/聚焦时丢失。不将其设置为UIResource,即
public static void setUIFont(Font a){
// force usage of the button's font as set by optionPaneUI
// by _not_ making it a uiResource
UIManager.put("OptionPane.buttonFont", a);
// use uiResource for others
FontUIResource ax=new FontUIResource(a);
UIManager.put("OptionPane.messageFont", ax);
...
}
通常情况下,不是最好的想法。但是我们在这里可以不使用它,因为每个对JOptionPane.create的调用都会创建按钮,而不会对单个实例产生持久的影响。
https://stackoverflow.com/questions/15490501
复制相似问题