Example usage for javax.swing JOptionPane showMessageDialog

List of usage examples for javax.swing JOptionPane showMessageDialog

Introduction

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

Prototype

public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType)
        throws HeadlessException 

Source Link

Document

Brings up a dialog that displays a message using a default icon determined by the messageType parameter.

Usage

From source file:Main.java

public static void main(String... args) throws Exception {
    JPanel panel = new JPanel();
    panel.setOpaque(true);/*  w w  w. j av  a2  s.  c  o  m*/
    panel.setBackground(Color.RED);

    java.net.URL url = new java.net.URL("http://www.java2s.com/style/download.png");
    ImageIcon image = new ImageIcon(url);
    JLabel label = new JLabel("LABEL", image, JLabel.RIGHT);
    panel.add(label);

    JOptionPane.showMessageDialog(null, panel, "Modified JOptionPane : ", JOptionPane.PLAIN_MESSAGE);
}

From source file:Main.java

public static void main(String args[]) {
    ProgressMonitorInputStream monitor;
    try {/* www  . j  a  v  a 2 s .co  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:Main.java

public static void main(String[] args) {
    String text = "one two three four five six seven eight nine ten ";
    JTextArea textArea = new JTextArea(text);
    textArea.setColumns(30);//w  w  w.j a va 2  s . c  o m
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.append(text);
    textArea.append(text);
    textArea.append(text);
    textArea.append(text);
    textArea.append(text);
    textArea.setSize(textArea.getPreferredSize().width, 1);
    JOptionPane.showMessageDialog(null, new JScrollPane(textArea), "Not Truncated!",
            JOptionPane.WARNING_MESSAGE);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    Image chunk = readFragment(url.openStream(), new Rectangle(15, 15, 30, 25));
    JOptionPane.showMessageDialog(null, new ImageIcon(chunk), "Duke", JOptionPane.INFORMATION_MESSAGE);

}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    Box box = Box.createVerticalBox();
    for (int i = 0; i < 100; i++) {
        box.add(new JLabel("Hello!"));
    }/*from   w w  w .ja  v  a2  s.com*/
    panel.add(box);

    JTabbedPane tab = new JTabbedPane();
    JScrollPane scroll = new JScrollPane(panel);
    scroll.setPreferredSize(new Dimension(300, 300));
    tab.add(scroll, "Panel 1");

    JOptionPane.showMessageDialog(null, tab, "Test Tabbed", JOptionPane.PLAIN_MESSAGE);
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    BufferedImage large = ImageIO.read(new File("images/a.jpg"));
    BufferedImage small = ImageIO.read(new File("images/b.jpg"));

    int w = large.getWidth();
    int h = large.getHeight();
    int type = BufferedImage.TYPE_INT_RGB;

    BufferedImage image = new BufferedImage(w, h, type);
    Graphics2D g2 = image.createGraphics();
    g2.drawImage(large, 0, 0, null);//from  www  . j  a v  a  2s  .c  om
    g2.drawImage(small, 10, 10, null);
    g2.dispose();
    ImageIO.write(image, "jpg", new File("new.jpg"));

    JOptionPane.showMessageDialog(null, new ImageIcon(image), "", JOptionPane.PLAIN_MESSAGE);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ImageIcon icon = new ImageIcon(new URL("http://www.java2s.com/style/download.png"));
    JLabel iconLabel = new JLabel(icon);
    JPanel iconPanel = new JPanel(new GridBagLayout());
    iconPanel.add(iconLabel);//w ww  . j  a va2s. c  om

    JPanel textPanel = new JPanel(new GridLayout(0, 1));
    for (int i = 0; i < 15; i++) {
        textPanel.add(new JLabel("Hello"));
    }

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textPanel);
    mainPanel.add(iconPanel, BorderLayout.WEST);
    JOptionPane.showMessageDialog(null, mainPanel, "Center Image Dialog", JOptionPane.PLAIN_MESSAGE);
}

From source file:Main.java

public static void main(String[] args) {
    List<Phone> phones = new ArrayList<>();
    phones.add(new Phone("Galaxy", 12345));
    phones.add(new Phone("iPhone", 12345));

    JPanel panel = new JPanel(new GridLayout(0, 1));
    for (Phone phone : phones) {
        String html = "<html><body style='width:100px'>Phone: " + phone.getName() + "<br/>Model: "
                + phone.getModel() + "</body></html>";
        JLabel label = new JLabel(html);
        label.setBorder(new MatteBorder(0, 0, 1, 0, Color.BLACK));
        panel.add(label);/*from  w  ww  .  j a  v a  2  s .  co m*/

    }
    JOptionPane.showMessageDialog(null, panel, "Phone List", JOptionPane.PLAIN_MESSAGE);
}

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;
            }/*from   www .  j a v  a2 s. co  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  a  v a  2s.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);

}