/** * Brings up a sheet with a specified icon, where the initial choice is determined by the {@code * initialValue} parameter and the number of choices is determined by the {@code optionType} * parameter. * * <p>If {@code optionType} is {@code YES_NO_OPTION}, or {@code YES_NO_CANCEL_OPTION} and the * {@code options} parameter is {@code null}, then the options are supplied by the look and feel. * * <p>The {@code messageType} parameter is primarily used to supply a default icon from the look * and feel. * * @param parentComponent determines the {@code Frame} in which the dialog is displayed; if {@code * null}, or if the {@code parentComponent} has no {@code Frame}, the sheet is displayed as a * dialog. * @param message the {@code Object} to display * @param optionType an integer designating the options available on the dialog: {@code * YES_NO_OPTION}, or {@code YES_NO_CANCEL_OPTION} * @param messageType an integer designating the kind of message this is, primarily used to * determine the icon from the pluggable Look and Feel: {@code JOptionPane.ERROR_MESSAGE}, * {@code JOptionPane.INFORMATION_MESSAGE}, {@code JOptionPane.WARNING_MESSAGE}, {@code * JOptionPane.QUESTION_MESSAGE}, or {@code JOptionPane.PLAIN_MESSAGE} * @param icon the icon to display in the dialog * @param options an array of objects indicating the possible choices the user can make; if the * objects are components, they are rendered properly; non-{@code String} objects are rendered * using their {@code toString} methods; if this parameter is {@code null}, the options are * determined by the Look and Feel * @param initialValue the object that represents the default selection for the dialog; only * meaningful if {@code options} is used; can be {@code null} * @param listener The listener for SheetEvents. */ public static void showOptionSheet( Component parentComponent, Object message, int optionType, int messageType, Icon icon, Object[] options, Object initialValue, SheetListener listener) { JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, options, initialValue); pane.setInitialValue(initialValue); pane.setComponentOrientation( ((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent) .getComponentOrientation()); int style = styleFromMessageType(messageType); JSheet sheet = createSheet(pane, parentComponent, style); pane.selectInitialValue(); sheet.addSheetListener(listener); sheet.show(); sheet.toFront(); }
/** * Prompts the user for input in a sheet where the initial selection, possible selections, and all * other options can be specified. The user will able to choose from {@code selectionValues}, * where {@code null} implies the user can input whatever they wish, usually by means of a {@code * JTextField}. {@code initialSelectionValue} is the initial value to prompt the user with. It is * up to the UI to decide how best to represent the {@code selectionValues}, but usually a {@code * JComboBox}, {@code JList}, or {@code JTextField} will be used. * * @param parentComponent the parent {@code Component} for the dialog * @param message the {@code Object} to display * @param messageType the type of message to be displayed: {@code JOptionPane.ERROR_MESSAGE}, * {@code JOptionPane.INFORMATION_MESSAGE}, {@code JOptionPane.WARNING_MESSAGE}, {@code * JOptionPane.QUESTION_MESSAGE}, or {@code JOptionPane.PLAIN_MESSAGE} * @param icon the {@code Icon} image to display * @param selectionValues an array of {@code Object}s that gives the possible selections * @param initialSelectionValue the value used to initialize the input field * @param listener The listener for SheetEvents. */ public static void showInputSheet( Component parentComponent, Object message, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue, SheetListener listener) { JOptionPane pane = new JOptionPane(message, messageType, JOptionPane.OK_CANCEL_OPTION, icon, null, null); pane.setWantsInput(true); pane.setSelectionValues(selectionValues); pane.setInitialSelectionValue(initialSelectionValue); pane.setComponentOrientation( ((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent) .getComponentOrientation()); int style = styleFromMessageType(messageType); JSheet sheet = createSheet(pane, parentComponent, style); pane.selectInitialValue(); /* sheet.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { sheet.dispose(); } });*/ sheet.addSheetListener(listener); sheet.show(); sheet.toFront(); }