Class BasicOptionPaneUI
- Direct Known Subclasses:
SynthOptionPaneUI
public class BasicOptionPaneUI extends OptionPaneUI
JOptionPane. BasicMessagePaneUI provides a means to place an icon, message and buttons into a Container. Generally, the layout will look like:
------------------
| i | message |
| c | message |
| o | message |
| n | message |
------------------
| buttons |
|________________|
icon is an instance of Icon that is wrapped inside a JLabel. The message is an opaque object and is tested for the following: if the message is a Component it is added to the Container, if it is an Icon it is wrapped inside a JLabel and added to the Container otherwise it is wrapped inside a JLabel. The above layout is used when the option pane's ComponentOrientation property is horizontal, left-to-right. The layout will be adjusted appropriately for other orientations.
The Container, message, icon, and buttons are all determined from abstract methods.
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
class |
BasicOptionPaneUI.ButtonActionListener |
This class should be treated as a "protected" inner class. |
static class |
BasicOptionPaneUI.ButtonAreaLayout |
ButtonAreaLayout behaves in a similar manner to FlowLayout. |
class |
BasicOptionPaneUI.PropertyChangeHandler |
This class should be treated as a "protected" inner class. |
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
protected boolean |
hasCustomComponents |
This is set to true in validateComponent if a Component is contained in either the message or the buttons. |
protected Component |
initialFocusComponent |
Component to receive focus when messaged with selectInitialValue. |
protected JComponent |
inputComponent |
JComponent provide for input if optionPane.getWantsInput() returns true. |
static final int |
MinimumHeight |
The mininum height of JOptionPane. |
protected Dimension |
minimumSize |
The size of JOptionPane. |
static final int |
MinimumWidth |
The mininum width of JOptionPane. |
protected JOptionPane |
optionPane |
JOptionPane that the receiver is providing the look and feel for. |
protected PropertyChangeListener |
propertyChangeListener |
The instance of PropertyChangeListener. |
Constructor Summary
| Constructor | Description |
|---|---|
BasicOptionPaneUI() |
Constructs a BasicOptionPaneUI. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
protected void |
addButtonComponents |
Creates the appropriate object to represent each of the objects in buttons and adds it to container. |
protected void |
addIcon |
Creates and adds a JLabel representing the icon returned from getIcon to top. |
protected void |
addMessageComponents |
Creates the appropriate object to represent msg and places it into container. |
protected void |
burstStringInto |
Recursively creates new JLabel instances to represent d. |
boolean |
containsCustomComponents |
Returns true if in the last call to validateComponent the message or buttons contained a subclass of Component. |
protected ActionListener |
createButtonActionListener |
Constructs a new instance of a ButtonActionListener. |
protected Container |
createButtonArea() |
Creates and returns a Container containing the buttons. |
protected LayoutManager |
createLayoutManager() |
Returns a layout manager. |
protected Container |
createMessageArea() |
Messaged from installComponents to create a Container containing the body of the message. |
protected PropertyChangeListener |
createPropertyChangeListener() |
Returns an instance of PropertyChangeListener. |
protected Container |
createSeparator() |
Returns a separator. |
static ComponentUI |
createUI |
Creates a new BasicOptionPaneUI instance. |
protected Object[] |
getButtons() |
Returns the buttons to display from the JOptionPane the receiver is providing the look and feel for. |
protected Icon |
getIcon() |
Returns the icon from the JOptionPane the receiver is providing the look and feel for, or the default icon as returned from getDefaultIcon. |
protected Icon |
getIconForType |
Returns the icon to use for the passed in type. |
protected int |
getInitialValueIndex() |
Returns the initial index into the buttons to select. |
protected int |
getMaxCharactersPerLineCount() |
Returns the maximum number of characters to place on a line. |
protected Object |
getMessage() |
Returns the message to display from the JOptionPane the receiver is providing the look and feel for. |
Dimension |
getMinimumOptionPaneSize() |
Returns the minimum size the option pane should be. |
Dimension |
getPreferredSize |
If c is the JOptionPane the receiver is contained in, the preferred size that is returned is the maximum of the preferred size of the LayoutManager for the JOptionPane, and getMinimumOptionPaneSize. |
protected boolean |
getSizeButtonsToSameWidth() |
Returns true, basic L&F wants all the buttons to have the same width. |
protected void |
installComponents() |
Registers components. |
protected void |
installDefaults() |
Installs default properties. |
protected void |
installKeyboardActions() |
Registers keyboard actions. |
protected void |
installListeners() |
Registers listeners. |
void |
installUI |
Installs the receiver as the L&F for the passed in JOptionPane. |
protected void |
resetInputValue() |
Sets the input value in the option pane the receiver is providing the look and feel for based on the value in the inputComponent. |
void |
selectInitialValue |
If inputComponent is non-null, the focus is requested on that, otherwise request focus on the default value |
protected void |
uninstallComponents() |
Unregisters components. |
protected void |
uninstallDefaults() |
Uninstalls default properties. |
protected void |
uninstallKeyboardActions() |
Unregisters keyboard actions. |
protected void |
uninstallListeners() |
Unregisters listeners. |
void |
uninstallUI |
Removes the receiver from the L&F controller of the passed in split pane. |
Methods declared in class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, paint, update
Field Details
MinimumWidth
public static final int MinimumWidth
JOptionPane.- See Also:
MinimumHeight
public static final int MinimumHeight
JOptionPane.- See Also:
optionPane
protected JOptionPane optionPane
JOptionPane that the receiver is providing the look and feel for.minimumSize
protected Dimension minimumSize
JOptionPane.inputComponent
protected JComponent inputComponent
initialFocusComponent
protected Component initialFocusComponent
hasCustomComponents
protected boolean hasCustomComponents
propertyChangeListener
protected PropertyChangeListener propertyChangeListener
PropertyChangeListener.Constructor Details
BasicOptionPaneUI
public BasicOptionPaneUI()
BasicOptionPaneUI.Method Details
createUI
public static ComponentUI createUI(JComponent x)
BasicOptionPaneUI instance.- Parameters:
-
x- the component - Returns:
- a new
BasicOptionPaneUIinstance
installUI
public void installUI(JComponent c)
JOptionPane.- Overrides:
-
installUIin classComponentUI - Parameters:
-
c- the component where this UI delegate is being installed - See Also:
uninstallUI
public void uninstallUI(JComponent c)
- Overrides:
-
uninstallUIin classComponentUI - Parameters:
-
c- the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components - See Also:
installDefaults
protected void installDefaults()
uninstallDefaults
protected void uninstallDefaults()
installComponents
protected void installComponents()
uninstallComponents
protected void uninstallComponents()
createLayoutManager
protected LayoutManager createLayoutManager()
- Returns:
- a layout manager
installListeners
protected void installListeners()
uninstallListeners
protected void uninstallListeners()
createPropertyChangeListener
protected PropertyChangeListener createPropertyChangeListener()
PropertyChangeListener.- Returns:
- an instance of
PropertyChangeListener
installKeyboardActions
protected void installKeyboardActions()
uninstallKeyboardActions
protected void uninstallKeyboardActions()
getMinimumOptionPaneSize
public Dimension getMinimumOptionPaneSize()
- Returns:
- the minimum size of the option pane
getPreferredSize
public Dimension getPreferredSize(JComponent c)
c is the JOptionPane the receiver is contained in, the preferred size that is returned is the maximum of the preferred size of the LayoutManager for the JOptionPane, and getMinimumOptionPaneSize.- Overrides:
-
getPreferredSizein classComponentUI - Parameters:
-
c- the component whose preferred size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components - Returns:
- a
Dimensionobject containing given component's preferred size appropriate for the look and feel - See Also:
createMessageArea
protected Container createMessageArea()
installComponents to create a Container containing the body of the message. The icon is the created by calling addIcon.- Returns:
- a instance of
Container
addMessageComponents
protected void addMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)
msg and places it into container. If msg is an instance of Component, it is added directly; if it is an Icon, a JLabel is created to represent it; otherwise, a JLabel is created for the string. If msg is an Object[], this method will be recursively invoked for the children. internallyCreated is true if msg is an instance of Component and was created internally by this method (this is used to correctly set hasCustomComponents only if internallyCreated is false).- Parameters:
-
container- a container -
cons- an instance ofGridBagConstraints -
msg- a message -
maxll- a maximum length -
internallyCreated-trueif the component was internally created
getMessage
protected Object getMessage()
JOptionPane the receiver is providing the look and feel for.- Returns:
- the message to display
addIcon
protected void addIcon(Container top)
getIcon to top. This is messaged from createMessageArea.- Parameters:
-
top- a container
getIcon
protected Icon getIcon()
JOptionPane the receiver is providing the look and feel for, or the default icon as returned from getDefaultIcon.- Returns:
- the icon
getIconForType
protected Icon getIconForType(int messageType)
- Parameters:
-
messageType- a type of message - Returns:
- the icon to use for the passed in type
getMaxCharactersPerLineCount
protected int getMaxCharactersPerLineCount()
- Returns:
- the maximum number of characters to place on a line
burstStringInto
protected void burstStringInto(Container c, String d, int maxll)
JLabel instances to represent d. Each JLabel instance is added to c.- Parameters:
-
c- a container -
d- a text -
maxll- a maximum length of a text
createSeparator
protected Container createSeparator()
- Returns:
- a separator
createButtonArea
protected Container createButtonArea()
Container containing the buttons. The buttons are created by calling getButtons.- Returns:
- a
Containercontaining the buttons
addButtonComponents
protected void addButtonComponents(Container container, Object[] buttons, int initialIndex)
buttons and adds it to container. This differs from addMessageComponents in that it will recurse on buttons and that if button is not a Component it will create an instance of JButton.- Parameters:
-
container- a container -
buttons- an array of buttons -
initialIndex- an initial index
createButtonActionListener
protected ActionListener createButtonActionListener(int buttonIndex)
ButtonActionListener.- Parameters:
-
buttonIndex- an index of the button - Returns:
- a new instance of a
ButtonActionListener
getButtons
protected Object[] getButtons()
JOptionPane the receiver is providing the look and feel for. If the JOptionPane has options set, they will be provided, otherwise if the optionType is YES_NO_OPTION, yesNoOptions is returned, if the type is YES_NO_CANCEL_OPTION yesNoCancelOptions is returned, otherwise defaultButtons are returned.- Returns:
- the buttons to display from the JOptionPane
getSizeButtonsToSameWidth
protected boolean getSizeButtonsToSameWidth()
true, basic L&F wants all the buttons to have the same width.- Returns:
-
trueif all the buttons should have the same width
getInitialValueIndex
protected int getInitialValueIndex()
- Returns:
- the initial index into the buttons to select
resetInputValue
protected void resetInputValue()
selectInitialValue
public void selectInitialValue(JOptionPane op)
- Specified by:
-
selectInitialValuein classOptionPaneUI - Parameters:
-
op- aJOptionPane
containsCustomComponents
public boolean containsCustomComponents(JOptionPane op)
- Specified by:
-
containsCustomComponentsin classOptionPaneUI - Parameters:
-
op- aJOptionPane - Returns:
-
trueif the givenJOptionPanecontains user createdComponents
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/plaf/basic/BasicOptionPaneUI.html