📄 joptionpane.java
字号:
* This method changes the selectionValues property. * * @param newValues The new selectionValues. */ public void setSelectionValues(Object[] newValues) { if (newValues != selectionValues) { if (newValues != null) wantsInput = true; Object[] old = selectionValues; selectionValues = newValues; firePropertyChange(SELECTION_VALUES_PROPERTY, old, selectionValues); } } /** * This method sets the UI used with the JOptionPane. * * @param ui The UI used with the JOptionPane. */ public void setUI(OptionPaneUI ui) { super.setUI(ui); } /** * This method sets the value has been selected out of options. * * @param newValue The value that has been selected out of options. */ public void setValue(Object newValue) { if (value != newValue) { Object old = value; value = newValue; firePropertyChange(VALUE_PROPERTY, old, value); } } /** * This method changes the wantsInput property. * * @param newValue Whether this JOptionPane requires input. */ public void setWantsInput(boolean newValue) { if (wantsInput != newValue) { boolean old = wantsInput; wantsInput = newValue; firePropertyChange(WANTS_INPUT_PROPERTY, old, wantsInput); } } /** * This method shows a confirmation dialog with the title "Select an Option" * and displays the given message. The parent frame will be the same as the * parent frame of the given parentComponent. This method returns the * option chosen by the user. * * @param parentComponent The parentComponent to find a frame in. * @param message The message to display. * * @return The option that was selected. */ public static int showConfirmDialog(Component parentComponent, Object message) { JOptionPane pane = new JOptionPane(message); JDialog dialog = pane.createDialog(parentComponent, "Select an Option"); dialog.pack(); dialog.show(); return ((Integer) pane.getValue()).intValue(); } /** * This method shows a confirmation dialog with the given message, * optionType and title. The frame that owns the dialog will be the same * frame that holds the given parentComponent. This method returns the * option that was chosen. * * @param parentComponent The component to find a frame in. * @param message The message displayed. * @param title The title of the dialog. * @param optionType The optionType. * * @return The option that was chosen. */ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType) { JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType); JDialog dialog = pane.createDialog(parentComponent, title); dialog.pack(); dialog.show(); return ((Integer) pane.getValue()).intValue(); } /** * This method shows a confirmation dialog with the given message, title, * messageType and optionType. The frame owner will be the same frame as * the one that holds the given parentComponent. This method returns the * option selected by the user. * * @param parentComponent The component to find a frame in. * @param message The message displayed. * @param title The title of the dialog. * @param optionType The optionType. * @param messageType The messageType. * * @return The selected option. */ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) { JOptionPane pane = new JOptionPane(message, messageType, optionType); JDialog dialog = pane.createDialog(parentComponent, title); dialog.pack(); dialog.show(); return ((Integer) pane.getValue()).intValue(); } /** * This method shows a confirmation dialog with the given message, title, * optionType, messageType and icon. The frame owner will be the same as * the one that holds the given parentComponent. This method returns the * option selected by the user. * * @param parentComponent The component to find a frame in. * @param message The message displayed. * @param title The title of the dialog. * @param optionType The optionType. * @param messageType The messsageType. * @param icon The icon displayed. * * @return The selected option. */ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon) { JOptionPane pane = new JOptionPane(message, messageType, optionType, icon); JDialog dialog = pane.createDialog(parentComponent, title); dialog.pack(); dialog.show(); return ((Integer) pane.getValue()).intValue(); } /** * This method will show a QUESTION_MESSAGE input dialog with the given * message. No selectionValues is set so the Look and Feel will usually * give the user a TextField to fill out. The frame owner will be the same * frame that holds the given parentComponent. This method will return the * value entered by the user. * * @param parentComponent The component to find a frame in. * @param message The message displayed. * * @return The value entered by the user. */ public static String showInputDialog(Component parentComponent, Object message) { JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); pane.setWantsInput(true); JDialog dialog = pane.createDialog(parentComponent, null); dialog.pack(); dialog.show(); return (String) pane.getInputValue(); } /** * This method will show a QUESTION_MESSAGE type input dialog with the given * message and initialSelectionValue. Since there is no selectionValues * set, the Look and Feel will usually give a TextField to fill out. The * frame owner will be the same as the one that holds the given * parentComponent. This method will return the value entered by the user. * * @param parentComponent The component to find a frame in. * @param message The message to display. * @param initialSelectionValue The initially selected value. * * @return The value the user input. */ public static String showInputDialog(Component parentComponent, Object message, Object initialSelectionValue) { JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); pane.setInitialSelectionValue(initialSelectionValue); pane.setWantsInput(true); JDialog dialog = pane.createDialog(parentComponent, null); dialog.pack(); dialog.show(); return (String) pane.getInputValue(); } /** * This method displays a new input dialog with the given message, title and * messageType. Since no selectionValues value is given, the Look and Feel * will usually give the user a TextField to input data to. This method * returns the value the user inputs. * * @param parentComponent The component to find a frame in. * @param message The message to display. * @param title The title of the dialog. * @param messageType The messageType. * * @return The value the user input. */ public static String showInputDialog(Component parentComponent, Object message, String title, int messageType) { JOptionPane pane = new JOptionPane(message, messageType); pane.setWantsInput(true); JDialog dialog = pane.createDialog(parentComponent, title); dialog.pack(); dialog.show(); return (String) pane.getInputValue(); } /** * This method shows an input dialog with the given message, title, * messageType, icon, selectionValues, and initialSelectionValue. This * method returns the value that the user selects. * * @param parentComponent The component to find a frame in. * @param message The message displayed. * @param title The title of the dialog. * @param messageType The messageType. * @param icon The icon displayed. * @param selectionValues The list of values to select from. * @param initialSelectionValue The initially selected value. * * @return The user selected value. */ public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) { JOptionPane pane = new JOptionPane(message, messageType); pane.setWantsInput(true); pane.setIcon(icon); pane.setSelectionValues(selectionValues); pane.setInitialSelectionValue(initialSelectionValue); JDialog dialog = pane.createDialog(parentComponent, title); dialog.pack(); dialog.show(); return (String) pane.getInputValue(); } /** * This method shows a QUESTION_MESSAGE type input dialog. Since no * selectionValues is set, the Look and Feel will usually give the user a * TextField to input data to. This method returns the value the user * inputs. * * @param message The message to display. * * @return The user selected value. */ public static String showInputDialog(Object message) { JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); pane.setWantsInput(true); JDialog dialog = pane.createDialog(null, null); dialog.pack(); dialog.show(); return (String) pane.getInputValue(); } /** * This method shows a QUESTION_MESSAGE type input dialog. Since no * selectionValues is set, the Look and Feel will usually give the user a * TextField to input data to. The input component will be initialized with * the initialSelectionValue. This method returns the value the user * inputs. * * @param message The message to display. * @param initialSelectionValue The initialSelectionValue. * * @return The user selected value. */ public static String showInputDialog(Object message, Object initialSelectionValue) { JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); pane.setWantsInput(true); pane.setInitialSelectionValue(initialSelectionValue); JDialog dialog = pane.createDialog(null, null); dialog.pack(); dialog.show(); return (String) pane.getInputValue(); } /** * This method shows an internal confirmation dialog with the given message. * The internal frame dialog will be placed in the first JDesktopPane * ancestor of the given parentComponent. This method will return the value * selected. * * @param parentComponent The parent to find a JDesktopPane in. * @param message The message to display. * * @return The value selected. */ public static int showInternalConfirmDialog(Component parentComponent, Object message) { JOptionPane pane = new JOptionPane(message); JInternalFrame frame = pane.createInternalFrame(parentComponent, null); startModal(frame, pane); return ((Integer) pane.getValue()).intValue(); } /** * This method shows an internal confirmation dialog with the given message, * optionType and title. The internal frame dialog will be placed in the * first JDesktopPane ancestor of the given parentComponent. This method * will return the selected value. * * @param parentComponent The parent to find a JDesktopPane in. * @param message The message to display. * @param title The title to display. * @param optionType The option type. * * @return The selected value. */ public static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType) { JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); startModal(frame, pane); return ((Integer) pane.getValue()).intValue(); } /** * This method shows an internal confirmation dialog with the given message, * title, optionTypes and icon for the given message type. The internal * confirmation dialog will be placed in the first instance of * JDesktopPane ancestor of the given parentComponent. * * @param parentComponent The component to find a JDesktopPane in. * @param message The message to display. * @param title The title of the dialog. * @param optionType The option type. * @param messageType The message type. * * @return The selected value. */ public static int showInternalConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) { JOptionPane pane = new JOptionPane(message, messageType, optionType); JInternalFrame frame = pane.createInternalFrame(parentComponent, title); startModal(frame, pane); return ((Integer) pane.getValue()).intValue(); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -