Reputation: 31
How do I modify the size of the dialog box to be popped up when I call the showConfirmDialog()
method of the JOptionPane
class?
Upvotes: 3
Views: 4580
Reputation: 14806
You can create JPanel
and override it's getPreferredSize
method and return some desired dimension. Then add that JPanel
to your JOptionPane
.
Rough example:
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
Upvotes: 3