Example usage for javax.swing JOptionPane createDialog

List of usage examples for javax.swing JOptionPane createDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane createDialog.

Prototype

public JDialog createDialog(Component parentComponent, String title) throws HeadlessException 

Source Link

Document

Creates and returns a new JDialog wrapping this centered on the parentComponent in the parentComponent's frame.

Usage

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();// w  ww  .  j  a v a 2  s . c o m
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(2, 3));

    JPanel buttonConstrsint = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton getQuotesButton = new JButton("Load");
    buttonConstrsint.add(getQuotesButton);
    gui.add(buttonConstrsint, BorderLayout.NORTH);

    getQuotesButton.addActionListener(e -> {
        String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };

        Object[][] data = { { "A", "B", "Snowboarding", new Integer(5), new Boolean(false) },
                { "C", "D", "Pool", new Integer(10), new Boolean(false) } };

        JTable table = new JTable(data, columnNames);

        JScrollPane scrollPane = new JScrollPane(table);
        table.setFillsViewportHeight(true);

        gui.add(scrollPane, BorderLayout.CENTER);
        gui.revalidate();/* www. j a va2s.  c  om*/
        gui.repaint();
    });

    JOptionPane jOptionPane = new JOptionPane(gui);

    JDialog dialog = jOptionPane.createDialog(new JFrame(), "title");
    dialog.setSize(200, 200);
    dialog.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JOptionPane pane = new JOptionPane("your message", JOptionPane.ERROR_MESSAGE, JOptionPane.OK_OPTION);
    JDialog d = pane.createDialog(null, "title");
    d.pack();//from w ww .  j ava2  s  . co m
    d.setModal(false);
    d.setVisible(true);
    while (pane.getValue() == JOptionPane.UNINITIALIZED_VALUE) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException ie) {
        }
    }
    System.exit(0);
}

From source file:GettingJOptionPaneSelectionDemo.java

public static void main(String[] a) {

    String multiLineMsg[] = { "Hello,", "World" };
    JOptionPane pane = new JOptionPane();
    pane.setMessage(multiLineMsg);//from w w w  . j a  va  2  s  .c  o m
    JDialog d = pane.createDialog(null, "title");
    d.setVisible(true);
    int selection = getSelection(pane);

    switch (selection) {
    case JOptionPane.OK_OPTION:
        System.out.println("OK_OPTION");
        break;
    case JOptionPane.CANCEL_OPTION:
        System.out.println("CANCEL");
        break;
    default:
        System.out.println("Others");
    }

}

From source file:Main.java

public static void main(String[] args) {
    int TIME_VISIBLE = 3000;
    JFrame frame1 = new JFrame();
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame1.setSize(100, 100);//from www  . j  a  v a2s  .com
    frame1.setLocation(100, 100);

    JButton button = new JButton("My Button");
    frame1.getContentPane().add(button);

    button.addActionListener(e -> {
        JOptionPane pane = new JOptionPane("Message", JOptionPane.INFORMATION_MESSAGE);
        JDialog dialog = pane.createDialog(null, "Title");
        dialog.setModal(false);
        dialog.setVisible(true);

        new Timer(TIME_VISIBLE, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.setVisible(false);
            }
        }).start();
    });

    frame1.setVisible(true);

}

From source file:MainClass.java

public static void main(String[] a) {
    JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    JDialog dialog = optionPane.createDialog(null, "Manual Creation");
    dialog.setVisible(true);//from w ww .  j  a v a 2  s  .c  om
}

From source file:CreateDialogFromOptionPane.java

public static void main(final String[] args) {
    JFrame parent = new JFrame();
    JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    JDialog dialog = optionPane.createDialog(parent, "Manual Creation");
    dialog.setVisible(true);//from ww w.j  a v  a 2  s  . c o  m
}

From source file:MainClass.java

public static void main(String[] a) {

    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 optionPane = new JOptionPane();
    optionPane.setMessage(msg);/*w  w w .j ava  2s. com*/
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = optionPane.createDialog(null, "Width 100");
    dialog.setVisible(true);
}

From source file:ComplexMessageDemo.java

public static void main(String[] a) {

    Object complexMsg[] = { "Above Message", new ImageIcon("yourFile.gif"), new JButton("Hello"), new JSlider(),
            new ImageIcon("yourFile.gif"), "Below Message" };

    JOptionPane optionPane = new JOptionPane();
    optionPane.setMessage(complexMsg);/*from   w  w  w  .j  a va2s. co m*/
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = optionPane.createDialog(null, "Width 100");
    dialog.setVisible(true);
}

From source file:DisplayingMultilineMessages.java

public static void main(String[] a) {

    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 optionPane = new NarrowOptionPane();
    optionPane.setMessage(msg);//  w  w  w . java2  s  .  c o m
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = optionPane.createDialog(null, "Width 100");
    dialog.setVisible(true);
}