regionSelectDialog = new JDialog(editor, "Pick regions", true); regionPickerPanel = new RegionPickerPanel(this); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(regionPickerPanel); regionSelectDialog.setContentPane(scrollPane); regionSelectDialog.setDefaultCloseOperation( JDialog.HIDE_ON_CLOSE); addContent(0, 0, pickButton = new JButton("Pick Regions"), false, GridBagConstraints.WEST, GridBagConstraints.NONE);
final JOptionPane optionPane = new JOptionPane("Hello world", JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[]{}, null); final JDialog dialog = new JDialog(); dialog.setTitle("Message"); dialog.setModal(true); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.pack(); //create timer to dispose of dialog after 5 seconds Timer timer = new Timer(5000, new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { dialog.dispose(); } }); timer.setRepeats(false);//the timer should only go off once //start timer to close JDialog as dialog modal we must start the timer before its visible timer.start(); dialog.setVisible(true);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); passSomeTime(); this.setVisible(false); this.dispatchEvent(new WindowEvent( this, WindowEvent.WINDOW_CLOSING));
mainPanel.add(new JButton(new MyAction(frame, JDialog.DISPOSE_ON_CLOSE, "DISPOSE_ON_CLOSE"))); mainPanel.add(new JButton(new MyAction(frame, JDialog.HIDE_ON_CLOSE, "HIDE_ON_CLOSE"))); mainPanel.add(new JButton(new MyAction(frame, JDialog.DO_NOTHING_ON_CLOSE, "DO_NOTHING_ON_CLOSE"))); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); dialog = new JDialog(frame, title, false); dialog.setDefaultCloseOperation(defaultCloseOp); dialog.setPreferredSize(new Dimension(300, 200)); dialog.pack(); dialog.addWindowListener(new WindowAdapter() { @Override dialog.setVisible(true);
dialog = new javax.swing.JDialog(parentDlg, title, true); } else { dialog = new javax.swing.JDialog(frame, title, true); dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); contentPane.add(chooser, BorderLayout.CENTER);
public void run() { StringBuilder sb = new StringBuilder("<p>There were errors:</p><table border=1 cellspacing=1 cellpadding=1>"); for (ObjectName on : result.keySet()) { Throwable t = ExceptionHelper.getRootCause(result.get(on)); appContext.log(t); sb.append("<tr><td>"); sb.append(on.getKeyProperty("name")); sb.append(":"); sb.append("</td><td>"); sb.append(t.getLocalizedMessage()); sb.append("</td></tr>"); } sb.append("</table>"); setMsgText(sb.toString()); JButton btn = new JButton("Close"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { waitDialog.setVisible(false); } }); JPanel btnPanel = new JPanel(new FlowLayout()); btnPanel.add(btn); waitDialog.getContentPane().add(btnPanel, BorderLayout.SOUTH); waitDialog.getRootPane().setWindowDecorationStyle(JRootPane.ERROR_DIALOG); waitDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Dimension size = waitDialog.getSize(); waitDialog.pack(); waitDialog.setSize(size); } });
dialog.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); JButton button = new JButton("Hit me!"); button.addActionListener(new ActionListener()
private void initComponents(final JDialog dialog) { dialog.setLayout(new BorderLayout()); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.getContentPane().add(editorPanel, BorderLayout.CENTER); dialog.setPreferredSize(DEF_SIZE); dialog.setMinimumSize(MIN_SIZE); dialog.pack(); } });
public void run() { if (progressLabel == null) initComponents(); DialogDescriptor dd = createDialogDescriptor(caption, message, controller); Dialog d = DialogDisplayer.getDefault().createDialog(dd); d.pack(); owner = d; if (owner instanceof JDialog) { ((JDialog)owner).setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); } d.setVisible(true); } });
import javax.swing.JDialog; import javax.swing.JFrame; public class MyDialog { private JFrame frame = new JFrame(); private JDialog dialog = new JDialog(); public MyDialog() { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); frame.setVisible(true); //dialog = new JDialog(frame, JDialog.ModalityType.TOOLKIT_MODAL); dialog = new JDialog(frame, true); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setModal(true); dialog.setSize(300, 200); dialog.setVisible(true); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { MyDialog dialog = new MyDialog(); } }); } }
setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); @Override public void run() { new CustomDialog(null, "David").setVisible(true);
this.add(new JLabel("Dialog close test.", JLabel.CENTER)); this.add(new JButton(new AbstractAction("Close") { DialogClose.this.setVisible(false); DialogClose.this.dispatchEvent(new WindowEvent( DialogClose.this, WindowEvent.WINDOW_CLOSING)); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true);
frame.addInternalFrameListener(InternalWindowListener.wrap(listener)); ((JDesktopPane) owner).add(frame); frame.getContentPane().add(panel); frame.pack(); return frame; final JDialog dialog = new JDialog((Frame) owner, title); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.addWindowListener(listener); dialog.getContentPane().add(panel); dialog.pack(); return dialog; final JDialog dialog = new JDialog((Dialog) owner, title); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.addWindowListener(listener); dialog.getContentPane().add(panel); dialog.pack(); return dialog;
regionSelectDialog = new JDialog(editor, "Pick regions", true); regionPickerPanel = new RegionPickerPanel(this); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(regionPickerPanel); regionSelectDialog.setContentPane(scrollPane); regionSelectDialog.setDefaultCloseOperation( JDialog.HIDE_ON_CLOSE); addContent(0, 0, pickButton = new JButton("Pick Regions"), false, GridBagConstraints.WEST, GridBagConstraints.NONE);
JDialog d = new JDialog((Frame) null, "Download symbols", false); d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); d.addWindowListener(new WindowAdapter() { @Override
private void initGUI() { JLabel label = new JLabel(this.message, SwingConstants.CENTER); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { WaitDialog.this.dialog.hide(); WaitDialog.this.cancelable.cancel(); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(cancelButton); this.dialog = new XBayaDialog(this.xbayaGUI, this.title, label, buttonPanel); this.dialog.getDialog().setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); this.dialog.getDialog().setCursor(SwingUtil.WAIT_CURSOR); this.dialog.getDialog().addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { shown(); } }); }
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.addWindowListener(new WindowAdapter() { try { DummyDialog d = new DummyDialog(); d.setVisible(true); } catch (Exception e) { e.printStackTrace();
import java.awt.Window; import javax.swing.JFrame; import javax.swing.JDialog; public class WhyNoDispose extends JDialog { public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { try { WhyNoDispose frame = new WhyNoDispose("my title"); frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public WhyNoDispose(String title) { super((JFrame)null, title); pack(); } }
initComponents(frame); frame.setPreferredSize(new Dimension(300, 300));//testing purposes frame.pack(); frame.setVisible(true); final JDialog emailDialog = new JDialog(frame); emailDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); emailDialog.setLayout(new BorderLayout()); JButton sendMailBtn = new JButton("Send Email"); sendMailBtn.addActionListener(new ActionListener() { final JDialog emailProgressDialog = new JDialog(frame); emailProgressDialog.add(new JLabel("Mail in progress")); emailProgressDialog.pack(); emailProgressDialog.setVisible(true); emailDialog.add(sendMailBtn, BorderLayout.SOUTH); emailDialog.pack(); JButton openDialog = new JButton("Open emailDialog"); openDialog.addActionListener(new ActionListener() { emailDialog.setVisible(true); frame.getContentPane().add(openDialog);
dialog = new javax.swing.JDialog(parentDlg, title, true); } else { dialog = new javax.swing.JDialog(frame, title, true); dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); contentPane.add(chooser, BorderLayout.CENTER);