List of usage examples for javax.swing JDialog show
@Deprecated public void show()
From source file:MessageDialog.java
public static void main(String argv[]) { String message = "William Shakespeare was born\n" + "on April 23, 1564 in\n" + "Stratford-on-Avon near London."; JOptionPane pane = new JOptionPane(message); JDialog dialog = pane.createDialog(new JFrame(), "Dilaog"); dialog.show(); }
From source file:AskingQuestionDialog.java
public static void main(String argv[]) { JOptionPane pane = new JOptionPane("To be or not to be ?\nThat is the question."); Object[] options = new String[] { "To be", "Not to be" }; pane.setOptions(options);// w w w . j a v a 2s . c o m JDialog dialog = pane.createDialog(new JFrame(), "Dilaog"); dialog.show(); Object obj = pane.getValue(); int result = -1; for (int k = 0; k < options.length; k++) if (options[k].equals(obj)) result = k; System.out.println("User's choice: " + result); }
From source file:SimpleAboutDialog.java
public static void main(String[] args) { JDialog f = new SimpleAboutDialog(new JFrame()); f.show(); }
From source file:ManualDisplayPopup.java
public static void main(String args[]) { JFrame frame = new JFrame("NoButton Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Ask"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); JDialog dialog = optionPane.createDialog(source, "Manual Creation"); dialog.show(); int selection = OptionPaneUtils.getSelection(optionPane); System.out.println(selection); }/*ww w.ja va2 s .c o m*/ }; button.addActionListener(actionListener); Container contentPane = frame.getContentPane(); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MessagePopup.java
public static void main(String args[]) { JFrame frame = new JFrame("Message Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Pop it"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); /*/*from w w w . ja v a 2s . c om*/ * // String msg = "this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message"; String * msg = " <html>this is a really long message <br> this is a * really long message this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message"; * JOptionPane.showMessageDialog(source, msg); JOptionPane * optionPane = OptionPaneUtils.getNarrowOptionPane(72); * optionPane.setMessage(msg); * optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); * JDialog dialog = optionPane.createDialog(source, "Width 72"); * dialog.show(); int selection = * OptionPaneUtils.getSelection(optionPane); * JOptionPane.showMessageDialog(source, msg); String * multiLineMsg[] = {"Hello", "World"}; * JOptionPane.showMessageDialog(source, multiLineMsg); * * Object complexMsg[] = {"Above Message", new * DiamondIcon(Color.red), new JButton ("Hello"), new JSlider(), * new DiamondIcon(Color.blue), "Below Message"}; * JOptionPane.showInputDialog(source, complexMsg); JOptionPane * optionPane = new JOptionPane(); JSlider slider = * OptionPaneUtils.getSlider(optionPane); * optionPane.setMessage(new Object[] {"Select a value: " , * slider}); * optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE); * optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); * JDialog dialog = optionPane.createDialog(source, "My * Slider"); dialog.show(); System.out.println ("Input: " + * optionPane.getInputValue()); */ JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("I got an icon and a text label"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); Icon icon = new DiamondIcon(Color.blue); JButton jButton = OptionPaneUtils.getButton(optionPane, "OK", icon); optionPane.setOptions(new Object[] { jButton }); JDialog dialog = optionPane.createDialog(source, "Icon/Text Button"); dialog.show(); } }; button.addActionListener(actionListener); Container contentPane = frame.getContentPane(); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:CreateColorSamplePopup.java
public static void main(String args[]) { JFrame frame = new JFrame("JColorChooser Create Popup Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); final JButton button = new JButton("Pick to Change Background"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color initialBackground = button.getBackground(); final JColorChooser colorChooser = new JColorChooser(initialBackground); // colorChooser.setPreviewPanel(new JPanel()); final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER); previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); colorChooser.setPreviewPanel(previewLabel); // Bug workaround colorChooser.updateUI();/*from www. j a v a2s .co m*/ // For okay button selection, change button background to // selected color ActionListener okActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color newColor = colorChooser.getColor(); if (newColor.equals(button.getForeground())) { System.out.println("Color change rejected"); } else { button.setBackground(colorChooser.getColor()); } } }; // For cancel button selection, change button background to red ActionListener cancelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { button.setBackground(Color.red); } }; final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser, okActionListener, cancelActionListener); // Wait until current event dispatching completes before showing // dialog Runnable showDialog = new Runnable() { public void run() { dialog.show(); } }; SwingUtilities.invokeLater(showDialog); } }; button.addActionListener(actionListener); contentPane.add(button, BorderLayout.CENTER); frame.setSize(300, 100); frame.setVisible(true); }
From source file:DefaultButton.java
public static void main(String[] a) { JDialog f = new JDialog(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from w w w . j a v a 2 s .c o m } }); JButton btOK = new JButton("Press Enter to click me, I am the default."); btOK.setToolTipText("Save and exit"); f.getRootPane().setDefaultButton(btOK); JPanel p = new JPanel(); p.add(btOK); p.add(new JButton("I am NOT the default.")); f.getContentPane().add(p); f.pack(); f.setSize(new Dimension(300, 200)); f.show(); }
From source file:FrameKey.java
public static void main(String args[]) { final JFrame frame = new JFrame("Frame Key"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { JDialog dialog = new EscapeDialog(frame, "Hey"); JButton button = new JButton("Okay"); ActionListener innerActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Dialog Button Selected"); }//from w ww .j av a2 s .co m }; button.addActionListener(innerActionListener); dialog.getContentPane().add(button, BorderLayout.SOUTH); dialog.setSize(200, 200); dialog.show(); } }; JPanel content = (JPanel) frame.getContentPane(); KeyStroke stroke = KeyStroke.getKeyStroke("M"); InputMap inputMap = content.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "OPEN"); content.getActionMap().put("OPEN", actionListener); frame.setSize(300, 300); frame.setVisible(true); }
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 ww w .j a va 2 s. 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:freemind.controller.Controller.java
public static Color showCommonJColorChooserDialog(Component component, String title, Color initialColor) throws HeadlessException { final JColorChooser pane = getCommonJColorChooser(); pane.setColor(initialColor);//from w w w . ja va 2 s . com ColorTracker ok = new ColorTracker(pane); JDialog dialog = JColorChooser.createDialog(component, title, true, pane, ok, null); dialog.addWindowListener(new Closer()); dialog.addComponentListener(new DisposeOnClose()); dialog.show(); // blocks until user brings dialog down... return ok.getColor(); }