Example usage for javax.swing JOptionPane setMessage

List of usage examples for javax.swing JOptionPane setMessage

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The optionpane's message object.")
public void setMessage(Object newMessage) 

Source Link

Document

Sets the option pane's message-object.

Usage

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  w  w.j av a  2s  .  co  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);
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = optionPane.createDialog(null, "Width 100");
    dialog.setVisible(true);/*  w w  w  .j  ava  2s.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);
    optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
    JDialog dialog = optionPane.createDialog(null, "Width 100");
    dialog.setVisible(true);/* w w  w  . j a  v a  2 s  .  c o  m*/
}

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

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 ww w  .j  a va 2s . co m

}

From source file:GettingJOptionPaneSelectionDemo.java

public static void main(String[] a) {

    String multiLineMsg[] = { "Hello,", "World" };
    JOptionPane pane = new JOptionPane();
    pane.setMessage(multiLineMsg);
    JDialog d = pane.createDialog(null, "title");
    d.setVisible(true);//  w w w. jav a  2 s .co m
    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: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);/*from w w  w. j  a  va2 s  .c  om*/
    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();

            /*// w w  w .  j  a  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:Main.java

/** Show a message dialog box with message word wrapping, specified
 * title and type.  Type must be one of the JOptionPane *_MESSAGE
 * constants./*from w w w . ja v a  2s .c o 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   ww  w .  j a  va2 s  . com
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();
    }
}