Module java.desktop

Class BasicOptionPaneUI

Direct Known Subclasses:

public class BasicOptionPaneUI extends OptionPaneUI
Provides the basic look and feel for a 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.

  • Field Details

    • MinimumWidth

      public static final int MinimumWidth
      The minimum width of JOptionPane.
      See Also:
    • MinimumHeight

      public static final int MinimumHeight
      The minimum height of JOptionPane.
      See Also:
    • optionPane

      protected JOptionPane optionPane
      JOptionPane that the receiver is providing the look and feel for.
    • minimumSize

      protected Dimension minimumSize
      The size of JOptionPane.
    • inputComponent

      protected JComponent inputComponent
      JComponent provide for input if optionPane.getWantsInput() returns true.
    • initialFocusComponent

      protected Component initialFocusComponent
      Component to receive focus when messaged with selectInitialValue.
    • hasCustomComponents

      protected boolean hasCustomComponents
      This is set to true in validateComponent if a Component is contained in either the message or the buttons.
    • propertyChangeListener

      protected PropertyChangeListener propertyChangeListener
      The instance of PropertyChangeListener.
  • Constructor Details

    • BasicOptionPaneUI

      public BasicOptionPaneUI()
      Constructs a BasicOptionPaneUI.
  • Method Details

    • createUI

      public static ComponentUI createUI(JComponent x)
      Creates a new BasicOptionPaneUI instance.
      x - the component
      a new BasicOptionPaneUI instance
    • installUI

      public void installUI(JComponent c)
      Installs the receiver as the L&F for the passed in JOptionPane.
      installUI in class ComponentUI
      c - the component where this UI delegate is being installed
      See Also:
    • uninstallUI

      public void uninstallUI(JComponent c)
      Removes the receiver from the L&F controller of the passed in split pane.
      uninstallUI in class ComponentUI
      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()
      Installs default properties.
    • uninstallDefaults

      protected void uninstallDefaults()
      Uninstalls default properties.
    • installComponents

      protected void installComponents()
      Registers components.
    • uninstallComponents

      protected void uninstallComponents()
      Unregisters components.
    • createLayoutManager

      protected LayoutManager createLayoutManager()
      Returns a layout manager.
      a layout manager
    • installListeners

      protected void installListeners()
      Registers listeners.
    • uninstallListeners

      protected void uninstallListeners()
      Unregisters listeners.
    • createPropertyChangeListener

      protected PropertyChangeListener createPropertyChangeListener()
      Returns an instance of PropertyChangeListener.
      an instance of PropertyChangeListener
    • installKeyboardActions

      protected void installKeyboardActions()
      Registers keyboard actions.
    • uninstallKeyboardActions

      protected void uninstallKeyboardActions()
      Unregisters keyboard actions.
    • getMinimumOptionPaneSize

      public Dimension getMinimumOptionPaneSize()
      Returns the minimum size the option pane should be. Primarily provided for subclassers wishing to offer a different minimum size.
      the minimum size of the option pane
    • getPreferredSize

      public Dimension getPreferredSize(JComponent c)
      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.
      getPreferredSize in class ComponentUI
      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
      a Dimension object containing given component's preferred size appropriate for the look and feel
      See Also:
    • createMessageArea

      protected Container createMessageArea()
      Messaged from installComponents to create a Container containing the body of the message. The icon is the created by calling addIcon.
      a instance of Container
    • addMessageComponents

      protected void addMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)
      Creates the appropriate object to represent 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).
      container - a container
      cons - an instance of GridBagConstraints
      msg - a message
      maxll - a maximum length
      internallyCreated - true if the component was internally created
    • getMessage

      protected Object getMessage()
      Returns the message to display from the JOptionPane the receiver is providing the look and feel for.
      the message to display
    • addIcon

      protected void addIcon(Container top)
      Creates and adds a JLabel representing the icon returned from getIcon to top. This is messaged from createMessageArea.
      top - a container
    • getIcon

      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.
      the icon
    • getIconForType

      protected Icon getIconForType(int messageType)
      Returns the icon to use for the passed in type.
      messageType - a type of message
      the icon to use for the passed in type
    • getMaxCharactersPerLineCount

      protected int getMaxCharactersPerLineCount()
      Returns the maximum number of characters to place on a line.
      the maximum number of characters to place on a line
    • burstStringInto

      protected void burstStringInto(Container c, String d, int maxll)
      Recursively creates new JLabel instances to represent d. Each JLabel instance is added to c.
      c - a container
      d - a text
      maxll - a maximum length of a text
    • createSeparator

      protected Container createSeparator()
      Returns a separator.
      a separator
    • createButtonArea

      protected Container createButtonArea()
      Creates and returns a Container containing the buttons. The buttons are created by calling getButtons.
      a Container containing the buttons
    • addButtonComponents

      protected void addButtonComponents(Container container, Object[] buttons, int initialIndex)
      Creates the appropriate object to represent each of the objects in 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.
      container - a container
      buttons - an array of buttons
      initialIndex - an initial index
    • createButtonActionListener

      protected ActionListener createButtonActionListener(int buttonIndex)
      Constructs a new instance of a ButtonActionListener.
      buttonIndex - an index of the button
      a new instance of a ButtonActionListener
    • getButtons

      protected Object[] getButtons()
      Returns the buttons to display from the 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.
      the buttons to display from the JOptionPane
    • getSizeButtonsToSameWidth

      protected boolean getSizeButtonsToSameWidth()
      Returns true, basic L&F wants all the buttons to have the same width.
      true if all the buttons should have the same width
    • getInitialValueIndex

      protected int getInitialValueIndex()
      Returns the initial index into the buttons to select. The index is calculated from the initial value from the JOptionPane and options of the JOptionPane or 0.
      the initial index into the buttons to select
    • resetInputValue

      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.
    • selectInitialValue

      public void selectInitialValue(JOptionPane op)
      If inputComponent is non-null, the focus is requested on that, otherwise request focus on the default value
      Specified by:
      selectInitialValue in class OptionPaneUI
      op - a JOptionPane
    • containsCustomComponents

      public boolean containsCustomComponents(JOptionPane op)
      Returns true if in the last call to validateComponent the message or buttons contained a subclass of Component.
      Specified by:
      containsCustomComponents in class OptionPaneUI
      op - a JOptionPane
      true if the given JOptionPane contains user created Components