Example usage for javax.swing JOptionPane setMessageType

List of usage examples for javax.swing JOptionPane setMessageType

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The option pane's message type.")
public void setMessageType(int newType) 

Source Link

Document

Sets the option pane's message type.

Usage

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);//from   w w w. j a va2  s  .  c  om
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = optionPane.createDialog(null, "Width 100");
    dialog.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JOptionPane optionPane = new JOptionPane();
    optionPane.setMessage("Set Message");
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    optionPane.setOptions(new Object[] { new JButton("Button") });
    JDialog dialog = optionPane.createDialog(null, "Icon/Text Button");
    dialog.setVisible(true);/*from  w  ww.ja  v a  2 s  .c o m*/
}

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);/*ww  w.ja  v a 2  s  .c  o 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);//from  w  ww. java2 s  .  com
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = optionPane.createDialog(null, "Width 100");
    dialog.setVisible(true);
}

From source file:AddingButtonWithActionListener.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    JOptionPane optionPane = new JOptionPane();
    optionPane.setMessage("I got an icon and a text label");
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    Icon icon = new ImageIcon("yourFile.gif");
    JButton jButton = getButton(optionPane, "OK", icon);
    optionPane.setOptions(new Object[] { jButton });
    JDialog dialog = optionPane.createDialog(frame, "Icon/Text Button");
    dialog.setVisible(true);/*from w w w  .ja  va2 s. c  o  m*/

}

From source file:JSliderOnJOptionPane.java

public static void main(final String[] args) {
    JFrame parent = new JFrame();

    JOptionPane optionPane = new JOptionPane();
    JSlider slider = 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(parent, "My Slider");
    dialog.setVisible(true);/*  www  .j a  va 2s.  co  m*/
    System.out.println("Input: " + optionPane.getInputValue());
}

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();

            /*/* ww w  .  j a  v  a2  s . co m*/
             * // 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:Main.java

private static JOptionPane createPane(int type, String message, int messageMaxLength) {
    JOptionPane pane = createMaxLengthOptionPane(messageMaxLength);
    pane.setMessageType(type);
    pane.setMessage(message);// w  w w . ja  va 2s  .co  m
    return pane;
}

From source file:Main.java

/** Show a message dialog box with message word wrapping, specified
 * title and type.  Type must be one of the JOptionPane *_MESSAGE
 * constants./* w  w  w . j  ava 2s. co m*/
 *
 * @see JOptionPane.setMessageType */
public static void messageBox(Component parent, String title, int messageType, String message) {
    JOptionPane pane = makeWordWrapJOptionPane();
    pane.setMessage(message);
    pane.setMessageType(messageType);

    JDialog dialog = pane.createDialog(parent, title);
    dialog.setVisible(true);
}

From source file:Main.java

/** Show a confirmation message box with line wrapped message.
 *
 * 'optionType' is one of the JOptionPane.XXX_OPTION combination
 * constants, and the return value is one of the single-value
 * constants. *//*from w ww.j  a va2 s  . c o m*/
public static int confirmationBox(Component parent, String message, String title, int optionType) {
    JOptionPane pane = makeWordWrapJOptionPane();
    pane.setMessage(message);
    pane.setMessageType(JOptionPane.QUESTION_MESSAGE);
    pane.setOptionType(optionType);

    JDialog dialog = pane.createDialog(parent, title);
    dialog.setVisible(true);

    Object result = pane.getValue();
    if (result == null || !(result instanceof Integer)) {
        return JOptionPane.CLOSED_OPTION;
    } else {
        return ((Integer) result).intValue();
    }
}