final JDialog frame = new JDialog(parentFrame, frameTitle, true); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true);
protected JDialog createDialog(Component parent) { Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); JDialog dialog = new JDialog(frame, ("Select Font"), true); Action okAction = new DialogOKAction(dialog); Action cancelAction = new DialogCancelAction(dialog); JButton okButton = new JButton(okAction); okButton.setFont(DEFAULT_FONT); JButton cancelButton = new JButton(cancelAction); cancelButton.setFont(DEFAULT_FONT); JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new GridLayout(2, 1)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10)); ActionMap actionMap = buttonsPanel.getActionMap(); actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction); actionMap.put(okAction.getValue(Action.DEFAULT), okAction); InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT)); inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT)); JPanel dialogEastPanel = new JPanel(); dialogEastPanel.setLayout(new BorderLayout()); dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST); dialog.pack(); dialog.setLocationRelativeTo(frame); return dialog; }
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);
FIND_REPLACE_DIALOG.pack(); FIND_REPLACE_DIALOG.setLocationRelativeTo(frames[i]); FIND_REPLACE_DIALOG.setVisible(true); FIND_FIELD.requestFocusInWindow();
public void makeGui() { aPanel = new JPanel(new BorderLayout()); this.getContentPane().add(aPanel, BorderLayout.CENTER); Window win = SwingUtilities.getWindowAncestor(Example.this); JDialog dialog = new JDialog(win, "My Dialog", ModalityType.MODELESS); JPanel dialogPanel = new JPanel(); dialogPanel.setPreferredSize(new Dimension(200, 200)); dialog.add(dialogPanel); dialog.pack(); dialog.setVisible(true); JOptionPane.showMessageDialog(dialog, "arfarf"); }
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;
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(); } });
/** * Initializes UI. */ private void initUI() { // Use Border Layout setLayout(new BorderLayout()); // Create North Panel with Error Message and Button. JPanel northPanel = createNorthPanel(); add(northPanel, BorderLayout.NORTH); // Create Center Panel with Error Details. JScrollPane centerPanel = createCenterPanel(); add(centerPanel, BorderLayout.CENTER); // Repack and validate the owner owner.pack(); owner.validate(); }
@Override public void actionPerformed (ActionEvent arg0) { if(editor.isUsingDefaultTexture()) { JOptionPane.showMessageDialog(editor, "Load a Texture or an Atlas first."); return; } TextureAtlas atlas = editor.getAtlas(); if(atlas != null) regionPickerPanel.setAtlas(atlas); else regionPickerPanel.setTexture(editor.getTexture()); regionPickerPanel.revalidate(); regionPickerPanel.repaint(); regionSelectDialog.validate(); regionSelectDialog.repaint(); regionSelectDialog.pack(); regionSelectDialog.setVisible(true); } });
private static JDialog createDialog(Component parent, String title, JOptionPane optionPane, final JComponent defaultFocusedComponent) { JDialog dlg = optionPane.createDialog(parent, title); dlg.setLocationRelativeTo(parent); dlg.setResizable(true); dlg.pack(); return dlg; }
private void installPlugin(final File plugin) { final JDialog dialog = new JDialog(frame, "Installing Plugin", true); dialog.getContentPane().setLayout(new BorderLayout()); JProgressBar bar = new JProgressBar(); bar.setIndeterminate(true); bar.setString("Installing Plugin. Please wait..."); bar.setStringPainted(true); dialog.getContentPane().add(bar, BorderLayout.CENTER); dialog.pack(); dialog.setSize(225, 55); dialog.setLocationRelativeTo(frame); dialog.setVisible(true);
final JDialog dialog = new JDialog(frame, "Jar File Chooser", true); dialog.setLocation(location); final JList fileList = new JList(new Vector<>(files)); okay.setText("Okay"); okay.setToolTipText("Okay"); okay.addActionListener(evt -> dialog.setVisible(false)); JButton cancel = new javax.swing.JButton(); cancel.setText("Cancel"); cancel.addActionListener(evt -> { fileList.clearSelection(); dialog.setVisible(false); }); gridbag.setConstraints(cancel, constraints); dialog.add(cancel); dialog.pack(); dialog.setSize(dialog.getPreferredSize()); dialog.setVisible(true);
public void showNonModalDialog() { wizardDialog.setModal(false); wizardDialog.pack(); wizardDialog.setLocationRelativeTo(null); // center frame wizardDialog.setVisible(true); }
public static JDialog createDialogForPanel(JFrame parent, JPanel panel) { JDialog newdialog = new JDialog(parent); newdialog.getContentPane().add(panel, java.awt.BorderLayout.CENTER); newdialog.pack(); return newdialog; }
@Override public void actionPerformed (ActionEvent arg0) { if(editor.isUsingDefaultTexture()) { JOptionPane.showMessageDialog(editor, "Load a Texture or an Atlas first."); return; } TextureAtlas atlas = editor.getAtlas(); if(atlas != null) regionPickerPanel.setAtlas(atlas); else regionPickerPanel.setTexture(editor.getTexture()); regionPickerPanel.revalidate(); regionPickerPanel.repaint(); regionSelectDialog.validate(); regionSelectDialog.repaint(); regionSelectDialog.pack(); regionSelectDialog.setVisible(true); } });
private static JDialog createDialog(JComponent parent, String title, JOptionPane optionPane) { JDialog dlg = optionPane.createDialog(parent, title); dlg.setLocationRelativeTo(parent); dlg.setResizable(true); dlg.pack(); return dlg; } }
JPanel textPanel = new JPanel(new BorderLayout()); textPanel.setPreferredSize(new Dimension(100,100)); textPanel.add(text); System.out.println("encoding null!!"); setEncoding.setText(encoding); dialog.setVisible(false); }); useOldEncoding.addActionListener(e -> dialog.setVisible(false)); useAnotherEncoding.addActionListener(e -> { dialog.setVisible(false); alternateEncodingPrompt(encoding); }); dialog.getRootPane().setDefaultButton(useNewEncoding); dialog.pack(); dialog.setLocationRelativeTo(this); dialog.setVisible(true);
private void showProgressPanel(List<ComponentDescription> comps, boolean install) { final ProgressPanel pp = new ProgressPanel(comps, install); final JOptionPane optionPane = new JOptionPane(pp, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new String[] { "Abort" }, "Abort"); // optionPane.setPreferredSize(new Dimension(640,480)); final JDialog dialog = new JDialog((Frame) null, "Progress", false); dialog.setContentPane(optionPane); optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) { pp.requestExit(); dialog.setVisible(false); } } }); dialog.pack(); dialog.setVisible(true); new Thread(pp).start(); }
/** * Opens the dialog relative to <code>relativeTo</code>. * @param relativeTo some component */ public void open( Component relativeTo ){ dialog.pack(); dialog.setLocationRelativeTo( relativeTo ); validateBounds(); dialog.setVisible( true ); }
public static JDialog createDialogForPanel(JDialog parent, JPanel panel) { JDialog newdialog = new JDialog(parent); newdialog.getContentPane().add(panel, java.awt.BorderLayout.CENTER); newdialog.pack(); return newdialog; }