Here you can find the source of newModalDialog(JFrame owner, String title, JPanel content, JButton... buttons)
public static JDialog newModalDialog(JFrame owner, String title, JPanel content, JButton... buttons)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import javax.swing.Action; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JPanel; public class Main { /**/*from w w w . j ava 2 s . com*/ * Builds a standard modal input dialog, with content and buttons to * accept or cancel that content. */ public static JDialog newModalDialog(JFrame owner, String title, JPanel content, JButton... buttons) { java.awt.GridBagConstraints gridBagConstraints; int i = 0; for (JButton b : buttons) { i++; b.setPreferredSize(new java.awt.Dimension(100, 24)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = (i + 2); gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(3, 10, 3, 10); content.add(b, gridBagConstraints); } // // // JPanel buttonPanel = new JPanel(); // buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); // buttonPanel.setAlignmentX(0.0f); // buttonPanel.add(Box.createHorizontalGlue()); // for (int ii = 0 ; ii < buttons.length ; ii++) // { // if (ii > 0) // buttonPanel.add(interButtonSpace()); // buttonPanel.add(buttons[ii]); // } // // JPanel panel = new JPanel(); // panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // panel.setBorder(dialogBorder()); // panel.add(content); // panel.add(Box.createVerticalStrut(18)); // panel.add(buttonPanel); // JDialog theDialog = new JDialog(owner, title, true); theDialog.setContentPane(content); theDialog.pack(); return theDialog; } /** * Builds a standard modal input dialog, with content and buttons to * accept or cancel that content. */ public static JDialog newModalDialog(JFrame owner, String title, JPanel content, Action... actions) { JButton[] buttons = new JButton[actions.length]; for (int ii = 0; ii < actions.length; ii++) { buttons[ii] = new JButton(actions[ii]); } return newModalDialog(owner, title, content, buttons); } }