List of usage examples for javax.swing JDialog JDialog
public JDialog(Window owner, String title, Dialog.ModalityType modalityType)
From source file:Main.java
static public JDialog addModelessWindow(Frame mainWindow, Component jpanel, String title) { JDialog dialog = new JDialog(mainWindow, title, true); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(jpanel, BorderLayout.CENTER); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack();//from w w w. j a v a 2 s .com dialog.setLocationRelativeTo(mainWindow); dialog.setModalityType(ModalityType.MODELESS); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true); return dialog; }
From source file:Main.java
/** * Displays the given file chooser. Utility method for avoiding of memory leak in JDK * 1.3 {@link javax.swing.JFileChooser#showDialog}. * * @param chooser the file chooser to display. * @param parent the parent window.//from w w w. j a v a2s . c o m * @param approveButtonText the text for the approve button. * * @return the return code of the chooser. */ public static final int showJFileChooser(JFileChooser chooser, Component parent, String approveButtonText) { if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG); } Frame frame = (parent instanceof Frame) ? (Frame) parent : (Frame) javax.swing.SwingUtilities.getAncestorOfClass(java.awt.Frame.class, parent); String title = chooser.getDialogTitle(); if (title == null) { title = chooser.getUI().getDialogTitle(chooser); } final JDialog dialog = new JDialog(frame, title, true); dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(chooser, BorderLayout.CENTER); dialog.pack(); dialog.setLocationRelativeTo(parent); chooser.rescanCurrentDirectory(); final int[] retValue = new int[] { javax.swing.JFileChooser.CANCEL_OPTION }; ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent ev) { if (ev.getActionCommand() == JFileChooser.APPROVE_SELECTION) { retValue[0] = JFileChooser.APPROVE_OPTION; } dialog.setVisible(false); dialog.dispose(); } }; chooser.addActionListener(l); dialog.show(); return (retValue[0]); }
From source file:Main.java
public static JDialog getNewDialogForParentComponent(Component parent, String title, Dialog.ModalityType modal) { Frame frame = getParentFrameForCompomponent(parent); if (frame != null) { return new JDialog(frame, title, modal); } //else/* w w w .j a v a 2 s.c o m*/ Dialog dialog = getParentDialogForCompomponent(parent); if (dialog != null) { return new JDialog(dialog, title, modal); } //else throw new RuntimeException("Parent window of component is neither a frame nor a dialog!"); }
From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java
public static void show() throws JSONException { final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true); dialog.setSize(400, 250);//from w w w.j a v a 2 s . c om dialog.setLocationRelativeTo(Server.currentServer.frame); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel cp = new JPanel(new SpringLayout()); cp.add(new JLabel("Zielverzeichnis:")); JPanel panel = new JPanel(); final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path") ? Server.currentServer.settings.getString("backup.path") : ""), 10); panel.add(path); panel.add(new JButton(new AbstractAction("Whlen...") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText()) : new File(System.getProperty("user.home")))); jfc.setFileHidingEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle("Backup-Zielverzeichnis whlen"); if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) path.setText(jfc.getSelectedFile().getPath().replace("\\", "/")); } })); cp.add(panel); cp.add(new JLabel("")); cp.add(new JLabel("")); cp.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); cp.add(new JButton(new AbstractAction("Speichern") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { if (path.getText().length() > 0) Server.currentServer.settings.put("backup.path", path.getText()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } })); SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6); dialog.setContentPane(cp); dialog.pack(); dialog.setVisible(true); }
From source file:Main.java
/** * Displays an {@link JDialog}./*from w w w . j av a 2 s.c o m*/ * * @param parentComponent * @param title * @return */ public static void showDialog(Component parentComponent, JComponent component, String title) { final JDialog dialog; final Window window = getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame) window, title, true); } else { dialog = new JDialog((Dialog) window, title, true); } initDialog(dialog, component, parentComponent); dialog.setLocationRelativeTo(parentComponent); dialog.setVisible(true); }
From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java
public static void show(ClientFrame frame, final JSONArray data) { final JDialog dialog = new JDialog(frame, "Katalog whlen", true); dialog.setSize(400, 300);//from www . j av a 2 s.co m dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Client.currentClient.disconnect(); System.exit(0); } }); JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); dialog.setContentPane(contentPane); DefaultListModel dlm = new DefaultListModel(); for (int i = 0; i < data.length(); i++) { try { dlm.addElement(data.getJSONObject(i).getString("name")); } catch (JSONException e) { e.printStackTrace(); } } final JList catalogs = new JList(dlm); catalogs.setDragEnabled(false); catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); jsp.setPreferredSize(new Dimension(396, 200)); contentPane.add(jsp); JPanel mods = new JPanel(new GridLayout(1, 2)); mods.setPreferredSize(new Dimension(50, 22)); mods.add(new JButton(new AbstractAction("+") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(dialog, "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen", JOptionPane.PLAIN_MESSAGE); if (name != null && name.length() > 0) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); for (int i = 0; i < dlm.getSize(); i++) { if (dlm.get(i).toString().equals(name)) { JOptionPane.showMessageDialog(dialog, "Es existert bereits ein Katalog mit diesem Namen!", "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE); actionPerformed(e); return; } } try { dlm.addElement(name); JSONObject o = new JSONObject(); o.put("name", name); o.put("sources", new JSONArray()); o.put("tags", new JSONArray()); data.put(o); Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (Exception e1) { e1.printStackTrace(); } } } })); mods.add(new JButton(new AbstractAction("-") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { if (JOptionPane.showConfirmDialog(dialog, "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?", "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); data.remove(catalogs.getSelectedIndex()); dlm.remove(catalogs.getSelectedIndex()); try { Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (IOException e1) { e1.printStackTrace(); } } } } })); contentPane.add(mods); JLabel l = new JLabel(""); l.setPreferredSize(new Dimension(396, 14)); contentPane.add(l); JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); sep.setPreferredSize(new Dimension(396, 10)); contentPane.add(sep); JPanel buttons = new JPanel(new GridLayout(1, 2)); buttons.setPreferredSize(new Dimension(396, 22)); buttons.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Client.currentClient.disconnect(); System.exit(0); } })); buttons.add(new JButton(new AbstractAction("Katalog whlen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { try { Client.currentClient .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex()))); Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } } })); dialog.add(buttons); dialog.setLocationRelativeTo(frame); dialog.setResizable(false); dialog.setVisible(true); }
From source file:Main.java
public void launchDialog() { JButton findButton = new JButton("Find"); findButton.addActionListener(e -> { int start = text.getText().indexOf("is"); int end = start + "is".length(); if (start != -1) { text.requestFocus();// w w w.j a v a 2 s .c o m text.select(start, end); } }); JButton cancelButton = new JButton("Cancel"); JOptionPane optionPane = new JOptionPane("Do you understand?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, new Object[] { findButton, cancelButton }); JDialog dialog = new JDialog(frame, "Click a button", false); cancelButton.addActionListener(e -> dialog.setVisible(false)); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.setLocation(100, 100); dialog.pack(); dialog.setVisible(true); }
From source file:com.sshtools.common.ui.OptionsPanel.java
/** * * * @param parent//w ww. j a v a2 s. c o m * @param tabs tabs * * @return */ public static boolean showOptionsDialog(Component parent, OptionsTab[] tabs) { final OptionsPanel opts = new OptionsPanel(tabs); opts.reset(); JDialog d = null; Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent); if (w instanceof JDialog) { d = new JDialog((JDialog) w, "Options", true); } else if (w instanceof JFrame) { d = new JDialog((JFrame) w, "Options", true); } else { d = new JDialog((JFrame) null, "Options", true); } final JDialog dialog = d; // Create the bottom button panel final JButton cancel = new JButton("Cancel"); cancel.setMnemonic('c'); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { opts.cancelled = true; dialog.setVisible(false); } }); final JButton ok = new JButton("Ok"); ok.setMnemonic('o'); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (opts.validateTabs()) { dialog.setVisible(false); } } }); dialog.getRootPane().setDefaultButton(ok); JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(6, 6, 0, 0); gbc.weighty = 1.0; UIUtil.jGridBagAdd(buttonPanel, ok, gbc, GridBagConstraints.RELATIVE); UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER); JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); southPanel.add(buttonPanel); // JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPanel.add(opts, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); // Show the dialog dialog.getContentPane().setLayout(new GridLayout(1, 1)); dialog.getContentPane().add(mainPanel); dialog.pack(); dialog.setResizable(true); UIUtil.positionComponent(SwingConstants.CENTER, dialog); dialog.setVisible(true); if (!opts.cancelled) { opts.applyTabs(); } return !opts.cancelled; }
From source file:eu.delving.sip.actions.ImportAction.java
public ImportAction(JDesktopPane parent, SipModel sipModel) { configAction(this, "Import new source data", ICON_IMPORT, MENU_I); this.parent = parent; this.sipModel = sipModel; this.dialog = new JDialog(SwingUtilities.getWindowAncestor(parent), "Input Source", Dialog.ModalityType.APPLICATION_MODAL); setEnabled(false);/*w w w .j a v a2s . c o m*/ prepareDialog(); prepareChooser(sipModel); sipModel.getDataSetModel().addListener(new DataSetModel.SwingListener() { @Override public void stateChanged(DataSetModel model, DataSetState state) { setEnabled(state != ABSENT); } }); }
From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java
/** * Callback method for receiving notification of a mouse click on a chart. * * @param event information about the event. */// w w w . j ava2 s. com public void chartMouseClicked(ChartMouseEvent event) { if (event.getTrigger().getClickCount() > 1) { if (event.getEntity() instanceof XYItemEntity) { XYItemEntity item = (XYItemEntity) event.getEntity(); Component c = event.getTrigger().getComponent(); final JDialog dialog = new JDialog(JOptionPane.getFrameForComponent(c), "Item Data", false); dialog.setSize(400, 300); dialog.setLocation(getDialogLocation(dialog, c)); dialog.add(getItemPanel(dialog, item, event)); dialog.setVisible(true); } else { XYItemEntity item = (XYItemEntity) event.getEntity(); Component c = event.getTrigger().getComponent(); final JDialog dialog = new JDialog(JOptionPane.getFrameForComponent(c), "Item Data", false); dialog.setSize(400, 300); dialog.setLocation(getDialogLocation(dialog, c)); dialog.add(getSeriesPanel(dialog, event)); dialog.setVisible(true); } } else { if (!(event.getChart().getXYPlot().getRenderer() instanceof MotionBubbleRenderer)) { return; } MotionBubbleRenderer renderer = (MotionBubbleRenderer) event.getChart().getXYPlot().getRenderer(); MotionDataSet dataset = (MotionDataSet) event.getChart().getXYPlot().getDataset(); if (event.getEntity() instanceof XYItemEntity) { boolean selected; XYItemEntity entity = (XYItemEntity) event.getEntity(); int series = entity.getSeriesIndex(); int item = entity.getItem(); Object category = dataset.getCategory(series, item); if (category == null) { selected = !renderer.isSelectedItem(series, item); renderer.setSelectedItem(series, item, selected); } else { selected = !renderer.isSelectedCategory(category); renderer.setSelectedCategory(category, selected); } } } }