[英]how to handle option types in JOptionPane.showConfirmDialog
[英]How to resize a JOptionPane.showConfirmDialog
调用JOptionPane
类的showConfirmDialog()
方法时,如何修改要弹出的对话框的大小?
您可以创建JPanel
并覆盖它的getPreferredSize
方法并返回一些所需的尺寸。 然后将该JPanel
添加到您的JOptionPane
。
粗略的例子:
JPanel panel = new JPanel() {
@Override
public Dimension getPreferredSize() {
return new Dimension(320, 240);
}
};
//We can use JTextArea or JLabel to display messages
JTextArea textArea = new JTextArea();
textArea.setEditable(false);
panel.setLayout(new BorderLayout());
panel.add(new JScrollPane(textArea));
JOptionPane.showConfirmDialog(null,
panel, //Here goes content
"Here goes the title",
JOptionPane.OK_CANCEL_OPTION, // Options for JOptionPane
JOptionPane.ERROR_MESSAGE); // Message type
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.