show Component Dialog - Java Swing

Java examples for Swing:JOptionPane

Description

show Component Dialog

Demo Code


//package com.java2s;
import java.awt.Component;

import javax.swing.JComponent;

import javax.swing.JOptionPane;

public class Main {
    public static int showComponentDialog(Component comp,
            JComponent dialogPanel, String title) {
        Object[] message = new Object[1];
        message[0] = dialogPanel;/*from  w  w  w . j  av  a2s  .co  m*/
        int result = JOptionPane.showOptionDialog(comp, // the parent that the dialog blocks
                message, // the dialog message array
                title, // the title of the dialog window
                JOptionPane.NO_OPTION, // option type
                -1, // message type
                null, // optional icon, use null to use the default icon
                new String[] {}, // options string array, will be made into buttons
                null // option that should be made into a default button
                );
        return result;
    }

    public static int showComponentDialog(Component comp,
            JComponent dialogPanel, String title, String[] options) {
        Object[] message = new Object[1];
        message[0] = dialogPanel;
        int result = JOptionPane.showOptionDialog(comp, // the parent that the dialog blocks
                message, // the dialog message array
                title, // the title of the dialog window
                JOptionPane.NO_OPTION, // option type
                -1, // message type
                null, // optional icon, use null to use the default icon
                options, // options string array, will be made into buttons
                (options == null ? null : options[0]) // option that should be made into a default button
                );
        return result;
    }
}

Related Tutorials