Example usage for javax.swing JOptionPane ERROR_MESSAGE

List of usage examples for javax.swing JOptionPane ERROR_MESSAGE

Introduction

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

Prototype

int ERROR_MESSAGE

To view the source code for javax.swing JOptionPane ERROR_MESSAGE.

Click Source Link

Document

Used for error messages.

Usage

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 ww w. j a  v a 2 s.c  o  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:Main.java

public static void main(String argv[]) {
    String message = "line\n" + "line 2\n" + "line 3";
    JOptionPane.showMessageDialog(new JFrame(), message, "Dialog", JOptionPane.ERROR_MESSAGE);
}

From source file:JOptionPaneERROR_MESSAGE.java

public static void main(String[] args) {
    final JPanel panel = new JPanel();

    JOptionPane.showMessageDialog(panel, "Could not open file", "Error", JOptionPane.ERROR_MESSAGE);

}

From source file:ErrorDialog.java

public static void main(String argv[]) {
    String message = "\"The Comedy of Errors\"\n" + "is considered by many scholars to be\n"
            + "the first play Shakespeare wrote";
    JOptionPane.showMessageDialog(new JFrame(), message, "Dialog", JOptionPane.ERROR_MESSAGE);
}

From source file:Main.java

public static void main(String s[]) {
    JFileChooser chooser = new JFileChooser();
    int rc = chooser.showOpenDialog(null);
    while (rc == JFileChooser.APPROVE_OPTION && !chooser.getSelectedFile().getName().endsWith(".java")) {
        JOptionPane.showMessageDialog(null,
                "The file " + chooser.getSelectedFile() + " is not java source file.", "Open Error",
                JOptionPane.ERROR_MESSAGE);
        rc = chooser.showOpenDialog(null);
    }// w  ww  .jav a2 s. com
}

From source file:Main.java

public static void main(String args[]) {
    ProgressMonitorInputStream monitor;
    try {/*from ww  w  . jav a  2s  . c o  m*/
        monitor = new ProgressMonitorInputStream(null, "Loading ", new FileInputStream("yourFile.dat"));
        while (monitor.available() > 0) {
            byte[] data = new byte[38];
            monitor.read(data);
            System.out.write(data);
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Unable to find file: yourFile.dat", "Error",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:JOptionPaneDemonstrationLocalized.java

public static void main(String[] argv) {

        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font unicodeFont = new Font("LucidaSans", Font.PLAIN, 12);

        ResourceBundle bundle = ResourceBundle.getBundle("JOptionPaneResources", Locale.getDefault());

        String[] textMessages = new String[3];
        textMessages[0] = bundle.getString("Yes");
        textMessages[1] = bundle.getString("No");
        textMessages[2] = bundle.getString("Cancel");

        JOptionPane jop = new JOptionPane(bundle.getString("MessageText"), JOptionPane.ERROR_MESSAGE,
                JOptionPane.YES_NO_CANCEL_OPTION, null, textMessages);
        JDialog jopDialog = jop.createDialog(null, bundle.getString("TitleText"));
        jop.setFont(unicodeFont);/*from   w ww  .j a  v a2s  .  co m*/
        jopDialog.setVisible(true);
        Object userSelection = jop.getValue();
    }

From source file:AddingActionCommandActionListenerSample.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("Default Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textField = new JTextField();
    frame.add(textField, BorderLayout.NORTH);
    frame.add(new JTextField(), BorderLayout.SOUTH);

    InputVerifier verifier = new InputVerifier() {
        public boolean verify(JComponent input) {
            final JTextComponent source = (JTextComponent) input;
            String text = source.getText();
            if ((text.length() != 0) && !(text.equals("Exit"))) {
                JOptionPane.showMessageDialog(frame, "Can't leave.", "Error Dialog", JOptionPane.ERROR_MESSAGE);
                return false;
            } else {
                return true;
            }/*  w w  w.  j  a va  2 s  . c  o m*/
        }
    };
    textField.setInputVerifier(verifier);

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:ChangeLook.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("Change Look");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String lafClassName = null;
            lafClassName = actionEvent.getActionCommand();
            String finalLafClassName = lafClassName;
            try {
                UIManager.setLookAndFeel(finalLafClassName);
                SwingUtilities.updateComponentTreeUI(frame);
            } catch (Exception exception) {
                JOptionPane.showMessageDialog(frame, "Can't change look and feel", "Invalid PLAF",
                        JOptionPane.ERROR_MESSAGE);
            }//from w  w w  .  j  av  a2 s.  c o  m

        }
    };

    UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();

    JComboBox comboBox = new JComboBox(new String[] { "a", "b" });

    JPanel panel = new JPanel();

    for (int i = 0, n = looks.length; i < n; i++) {
        JButton button = new JButton(looks[i].getName());
        button.setActionCommand(looks[i].getClassName());
        button.addActionListener(actionListener);
        panel.add(button);
    }

    frame.add(comboBox, BorderLayout.NORTH);
    frame.add(panel, BorderLayout.SOUTH);
    frame.setSize(350, 150);
    frame.setVisible(true);

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField nameTextField = new JTextField();
    frame.add(nameTextField, BorderLayout.NORTH);
    frame.add(new JTextField(), BorderLayout.SOUTH);

    InputVerifier verifier = new InputVerifier() {
        public boolean verify(JComponent input) {
            final JTextComponent source = (JTextComponent) input;
            String text = source.getText();
            if ((text.length() != 0) && !(text.equals("Exit"))) {
                JOptionPane.showMessageDialog(source, "Can't leave.", "Error Dialog",
                        JOptionPane.ERROR_MESSAGE);
                return false;
            } else {
                return true;
            }//  w w  w .jav  a  2s .c om
        }
    };
    nameTextField.setInputVerifier(verifier);

    frame.setSize(250, 100);
    frame.setVisible(true);
}