[英]JOptionPane button size (Nimbus LAF)
Recently I've been working on a Swing project with Nimbus Look and Feel. 最近我一直在与Nimbus Look and Feel一起开展Swing项目。 I want to set all buttons in a JOptionPane to have the same size, but in vain.
我想将JOptionPane中的所有按钮设置为具有相同的大小,但是徒劳无功。
import javax.swing.*;
public class NimbusTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if (("Nimbus").equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
UIManager.put("OptionPane.sameSizeButtons", true);
String[] options = new String[]{"--------------------","short","1"};
int option = JOptionPane.showOptionDialog(null, "Nimbus problem", "JOptionPane", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
}
});
}
}
What I want is a JOptionPane with three buttons having the same size. 我想要的是一个JOptionPane,其中三个按钮具有相同的大小。 However, I got the following result:
但是,我得到了以下结果:
My code UIManager.put("OptionPane.sameSizeButtons", true);
我的代码
UIManager.put("OptionPane.sameSizeButtons", true);
seems to be ignored. 似乎被忽略了。 What should I do to create a JOptionPane with same size buttons if I don't want to recreate a JOptionPane-like dialog?
如果我不想重新创建类似JOptionPane的对话框,我该怎么做才能创建具有相同大小按钮的JOptionPane?
Replace 更换
UIManager.put("OptionPane.sameSizeButtons", true);
with 同
UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", true);
And it works like a charm 它就像一个魅力
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.