List of usage examples for javax.swing JDialog setContentPane
@BeanProperty(bound = false, hidden = true, description = "The client area of the dialog where child components are normally inserted.") public void setContentPane(Container contentPane)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400);/*from w w w . j a v a 2 s . co m*/ JDialog dialog = new JDialog(frame, "Dialog", true); JPanel mainGui = new JPanel(new BorderLayout()); mainGui.setBorder(new EmptyBorder(20, 20, 20, 20)); mainGui.add(new JLabel("Contents go here"), BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout()); mainGui.add(buttonPanel, BorderLayout.SOUTH); JButton close = new JButton("Close"); close.addActionListener(e -> dialog.setVisible(false)); buttonPanel.add(close); frame.setVisible(true); dialog.setContentPane(mainGui); dialog.pack(); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JDialog dialog; JList jlist;/*from ww w. ja va2 s . c o m*/ ActionListener otherListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("current"); } }; JButton okButton = new JButton("OK"); okButton.addActionListener(e -> close(true)); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(e -> close(false)); jlist = new JList(new String[] { "A", "B", "C", "D", "E", "F", "G" }); jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jlist.setVisibleRowCount(5); JScrollPane scroll = new JScrollPane(jlist); JPanel buttonsPanel = new JPanel(new FlowLayout()); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); JPanel content = new JPanel(new BorderLayout()); content.add(scroll, BorderLayout.CENTER); content.add(buttonsPanel, BorderLayout.SOUTH); dialog = new JDialog((Frame) null, true); dialog.setContentPane(content); dialog.pack(); dialog.getRootPane().registerKeyboardAction(otherListener, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); dialog.getRootPane().registerKeyboardAction(otherListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); dialog.getRootPane().getInputMap().put(KeyStroke.getKeyStroke("SPACE"), "doSomething"); dialog.getRootPane().getActionMap().put("doSomething", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); dialog.setVisible(true); }
From source file:org.matsim.contrib.util.chart.ChartWindowUtils.java
private static JDialog newChartDialog(JFreeChart chart, String title, boolean modal) { chart.setTitle(title);/*from w w w. j a va 2 s. co m*/ JDialog dialog = new JDialog(); dialog.setTitle(title); dialog.setContentPane(new ChartPanel(chart)); dialog.setModal(modal); dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); return dialog; }
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);//w w w . j av a2 s.c o 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
Main() { Object[][] data = { { "A", "B", "Snowboarding", new Integer(5) }, { "C", "D", "Pool", new Integer(10) } }; Object[] columnNames = { "firstname", "lastname", "age" }; final JTable table = new JTable(data, columnNames) { @Override/*from ww w . j av a 2 s. c om*/ public Dimension getPreferredScrollableViewportSize() { Dimension d = getPreferredSize(); int n = getRowHeight(); return new Dimension(d.width, (n * ROWS)); } }; JPanel jPanel = new JPanel(); jPanel.setLayout(new GridLayout()); JScrollPane sp = new JScrollPane(table); jPanel.add(sp); JDialog jdialog = new JDialog(); jdialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); jdialog.setContentPane(jPanel); jdialog.pack(); jdialog.setVisible(true); }
From source file:Main.java
/** * Adds a glass layer to the dialog to intercept all key events. If the * espace key is pressed, the dialog is disposed (either with a fadeout * animation, or directly)./*from ww w .j av a 2 s. co m*/ */ public static void addEscapeToCloseSupport(final JDialog dialog) { LayerUI<Container> layerUI = new LayerUI<Container>() { private boolean closing = false; @Override public void installUI(JComponent c) { super.installUI(c); ((JLayer) c).setLayerEventMask(AWTEvent.KEY_EVENT_MASK); } @Override public void uninstallUI(JComponent c) { super.uninstallUI(c); ((JLayer) c).setLayerEventMask(0); } @Override public void eventDispatched(AWTEvent e, JLayer<? extends Container> l) { if (e instanceof KeyEvent && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ESCAPE) { if (closing) { return; } closing = true; fadeOut(dialog); } } }; JLayer<Container> layer = new JLayer<Container>(dialog.getContentPane(), layerUI); dialog.setContentPane(layer); }
From source file:Main.java
public Main() { super(BoxLayout.Y_AXIS); Box info = Box.createVerticalBox(); info.add(new Label("Please wait 3 seconds")); final JButton continueButton = new JButton("Continue"); info.add(continueButton);// w w w. j a v a 2 s. c o m JDialog d = new JDialog(); d.setModalityType(ModalityType.APPLICATION_MODAL); d.setContentPane(info); d.pack(); continueButton.addActionListener(e -> d.dispose()); continueButton.setVisible(false); SwingWorker sw = new SwingWorker<Integer, Integer>() { protected Integer doInBackground() throws Exception { int i = 0; while (i++ < 30) { System.out.println(i); Thread.sleep(100); } return null; } @Override protected void done() { continueButton.setVisible(true); } }; JButton button = new JButton("Click Me"); button.addActionListener(e -> { sw.execute(); d.setVisible(true); }); add(button); }
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();/*from w ww . j av a2 s .co 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:Main.java
/** * Adds a glass layer to the dialog to intercept all key events. If the * espace key is pressed, the dialog is disposed (either with a fadeout * animation, or directly).//from ww w.j a v a 2s . co m */ public static void addEscapeToCloseSupport(final JDialog dialog, final boolean fadeOnClose) { LayerUI<Container> layerUI = new LayerUI<Container>() { private boolean closing = false; @Override public void installUI(JComponent c) { super.installUI(c); ((JLayer) c).setLayerEventMask(AWTEvent.KEY_EVENT_MASK); } @Override public void uninstallUI(JComponent c) { super.uninstallUI(c); ((JLayer) c).setLayerEventMask(0); } @Override public void eventDispatched(AWTEvent e, JLayer<? extends Container> l) { if (e instanceof KeyEvent && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ESCAPE) { if (closing) return; closing = true; if (fadeOnClose) fadeOut(dialog); else dialog.dispose(); } } }; JLayer<Container> layer = new JLayer<>(dialog.getContentPane(), layerUI); dialog.setContentPane(layer); }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.standalone.StandaloneShutdownDialog.java
private void displayShutdownDialog() { String serverId = ServerDetector.getServerId(); log.info("Running in: " + (serverId != null ? serverId : "unknown server")); log.info("Console: " + ((System.console() != null) ? "available" : "not available")); log.info("Headless: " + (GraphicsEnvironment.isHeadless() ? "yes" : "no")); // Show this only when run from the standalone JAR via a double-click if (System.console() == null && !GraphicsEnvironment.isHeadless() && ServerDetector.isWinstone()) { log.info("If you are running WebAnno in a server environment, please use '-Djava.awt.headless=true'"); EventQueue.invokeLater(new Runnable() { @Override/*from w w w.j av a 2s . com*/ public void run() { final JOptionPane optionPane = new JOptionPane(new JLabel( "<HTML>WebAnno is running now and can be accessed via <a href=\"http://localhost:8080\">http://localhost:8080</a>.<br>" + "WebAnno works best with the browsers Google Chrome or Safari.<br>" + "Use this dialog to shut WebAnno down.</HTML>"), JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_OPTION, null, new String[] { "Shutdown" }); final JDialog dialog = new JDialog((JFrame) null, "WebAnno", true); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { // Avoid closing window by other means than button } }); optionPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent aEvt) { if (dialog.isVisible() && (aEvt.getSource() == optionPane) && (aEvt.getPropertyName().equals(JOptionPane.VALUE_PROPERTY))) { System.exit(0); } } }); dialog.pack(); dialog.setVisible(true); } }); } else { log.info("Running in server environment or from command line: disabling interactive shutdown dialog."); } }