📄 joptionpane.java
字号:
* * @throws RuntimeException If no suitable JDesktopPane is found. * * @specnote The specification says that the internal frame is placed * in the nearest <code>JDesktopPane</code> that is found in * <code>parent</code>'s ancestors. The behaviour of the JDK * is that it actually looks up the nearest * <code>JLayeredPane</code> in <code>parent</code>'s ancestors. * So do we. */ public JInternalFrame createInternalFrame(Component parentComponent, String title) throws RuntimeException { // Try to find a JDesktopPane. JLayeredPane toUse = getDesktopPaneForComponent(parentComponent); // If we don't have a JDesktopPane, we try to find a JLayeredPane. if (toUse == null) toUse = JLayeredPane.getLayeredPaneAbove(parentComponent); // If this still fails, we throw a RuntimeException. if (toUse == null) throw new RuntimeException ("parentComponent does not have a valid parent"); JInternalFrame frame = new JInternalFrame(title); inputValue = UNINITIALIZED_VALUE; value = UNINITIALIZED_VALUE; frame.setContentPane(this); frame.setClosable(true); toUse.add(frame); frame.setLayer(JLayeredPane.MODAL_LAYER); frame.pack(); frame.setVisible(true); return frame; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public AccessibleContext getAccessibleContext() { if (accessibleContext == null) accessibleContext = new AccessibleJOptionPane(); return accessibleContext; } /** * This method returns the JDesktopPane for the given parentComponent or * null if none can be found. * * @param parentComponent The component to look in. * * @return The JDesktopPane for the given component or null if none can be * found. */ public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) { return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, parentComponent); } /** * This method returns the Frame for the given parentComponent or null if * none can be found. * * @param parentComponent The component to look in. * * @return The Frame for the given component or null if none can be found. */ public static Frame getFrameForComponent(Component parentComponent) { return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent); } /** * This method returns the icon displayed. * * @return The icon displayed. */ public Icon getIcon() { return icon; } /** * This method returns the value initially selected from the list of values * the user can input. * * @return The initial selection value. */ public Object getInitialSelectionValue() { return initialSelectionValue; } /** * This method returns the value that is focused from the list of options. * * @return The initial value from options. */ public Object getInitialValue() { return initialValue; } /** * This method returns the value that the user input. * * @return The user's input value. */ public Object getInputValue() { if (getValue().equals(new Integer(CANCEL_OPTION))) setInputValue(null); return inputValue; } /** * This method returns the maximum characters per line. By default, this is * Integer.MAX_VALUE. * * @return The maximum characters per line. */ public int getMaxCharactersPerLineCount() { return Integer.MAX_VALUE; } /** * This method returns the message displayed. * * @return The message displayed. */ public Object getMessage() { return message; } /** * This method returns the message type. * * @return The message type. */ public int getMessageType() { return messageType; } /** * This method returns the options. * * @return The options. */ public Object[] getOptions() { return options; } /** * This method returns the option type. * * @return The option type. */ public int getOptionType() { return optionType; } /** * This method returns the Frame used by JOptionPane dialog's that have no * parent. * * @return The Frame used by dialogs that have no parent. */ public static Frame getRootFrame() { return privFrame; } /** * This method returns the selection values. * * @return The selection values. */ public Object[] getSelectionValues() { return selectionValues; } /** * This method returns the UI used by the JOptionPane. * * @return The UI used by the JOptionPane. */ public OptionPaneUI getUI() { return (OptionPaneUI) ui; } /** * This method returns an identifier to determine which UI class will act as * the UI. * * @return The UI identifier. */ public String getUIClassID() { return "OptionPaneUI"; } /** * This method returns the value that the user selected out of options. * * @return The value that the user selected out of options. */ public Object getValue() { return value; } /** * This method returns whether this JOptionPane wants input. * * @return Whether this JOptionPane wants input. */ public boolean getWantsInput() { return wantsInput; } /** * This method returns a String that describes this JOptionPane. * * @return A String that describes this JOptionPane. */ protected String paramString() { return "JOptionPane"; } /** * This method requests focus for the initial value. */ public void selectInitialValue() { if (ui != null) ((OptionPaneUI) ui).selectInitialValue(this); } /** * This method changes the icon property. * * @param newIcon The new icon to use. */ public void setIcon(Icon newIcon) { if (icon != newIcon) { Icon old = icon; icon = newIcon; firePropertyChange(ICON_PROPERTY, old, icon); } } /** * This method changes the initial selection property. * * @param newValue The new initial selection. */ public void setInitialSelectionValue(Object newValue) { if (initialSelectionValue != newValue) { Object old = initialSelectionValue; initialSelectionValue = newValue; firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY, old, initialSelectionValue); } } /** * This method changes the initial value property. * * @param newValue The new initial value. */ public void setInitialValue(Object newValue) { if (initialValue != newValue) { Object old = initialValue; initialValue = newValue; firePropertyChange(INITIAL_VALUE_PROPERTY, old, initialValue); } } /** * This method changes the inputValue property. * * @param newValue The new inputValue. */ public void setInputValue(Object newValue) { if (inputValue != newValue) { Object old = inputValue; inputValue = newValue; firePropertyChange(INPUT_VALUE_PROPERTY, old, inputValue); } } /** * This method changes the message property. * * @param newMessage The new message. */ public void setMessage(Object newMessage) { if (message != newMessage) { Object old = message; message = newMessage; firePropertyChange(MESSAGE_PROPERTY, old, message); } } /** * This method changes the messageType property. * * @param newType The new messageType. * * @throws IllegalArgumentException If the messageType is not valid. */ public void setMessageType(int newType) { if (! validMessageType(newType)) throw new IllegalArgumentException("Message Type not legal value."); if (newType != messageType) { int old = messageType; messageType = newType; firePropertyChange(MESSAGE_TYPE_PROPERTY, old, messageType); } } /** * This method changes the options property. * * @param newOptions The new options. */ public void setOptions(Object[] newOptions) { if (options != newOptions) { Object[] old = options; options = newOptions; firePropertyChange(OPTIONS_PROPERTY, old, options); } } /** * This method changes the optionType property. * * @param newType The new optionType. * * @throws IllegalArgumentException If the optionType is not valid. */ public void setOptionType(int newType) { if (! validOptionType(newType)) throw new IllegalArgumentException("Option Type not legal value."); if (newType != optionType) { int old = optionType; optionType = newType; firePropertyChange(OPTION_TYPE_PROPERTY, old, optionType); } } /** * This method changes the Frame used for JOptionPane dialogs that have no * parent. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -