- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- javax.swing.plaf.OptionPaneUI
-
- javax.swing.plaf.basic.BasicOptionPaneUI
-
- Direct Known Subclasses:
- SynthOptionPaneUI
public class BasicOptionPaneUI extends OptionPaneUI
Provides the basic look and feel for aJOptionPane
.BasicMessagePaneUI
provides a means to place an icon, message and buttons into aContainer
. Generally, the layout will look like:------------------ | i | message | | c | message | | o | message | | n | message | ------------------ | buttons | |________________|
icon is an instance ofIcon
that is wrapped inside aJLabel
. The message is an opaque object and is tested for the following: if the message is aComponent
it is added to theContainer
, if it is anIcon
it is wrapped inside aJLabel
and added to theContainer
otherwise it is wrapped inside aJLabel
.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
Nested Classes Modifier and Type Class and Description class
BasicOptionPaneUI.ButtonActionListener
This class should be treated as a "protected" inner class.static class
BasicOptionPaneUI.ButtonAreaLayout
ButtonAreaLayout
behaves in a similar manner toFlowLayout
.class
BasicOptionPaneUI.PropertyChangeHandler
This class should be treated as a "protected" inner class.
-
Field Summary
Fields Modifier and Type Field and 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 int
MinimumHeight
protected Dimension
minimumSize
static int
MinimumWidth
protected JOptionPane
optionPane
JOptionPane
that the receiver is providing the look and feel for.protected PropertyChangeListener
propertyChangeListener
-
Constructor Summary
Constructors Constructor and Description BasicOptionPaneUI()
-
Method Summary
Methods Modifier and Type Method and Description protected void
addButtonComponents(Container container, Object[] buttons, int initialIndex)
Creates the appropriate object to represent each of the objects inbuttons
and adds it tocontainer
.protected void
addIcon(Container top)
Creates and adds a JLabel representing the icon returned fromgetIcon
totop
.protected void
addMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)
Creates the appropriate object to representmsg
and places it intocontainer
.protected void
burstStringInto(Container c, String d, int maxll)
Recursively creates new JLabel instances to representd
.boolean
containsCustomComponents(JOptionPane op)
Returns true if in the last call to validateComponent the message or buttons contained a subclass of Component.protected ActionListener
createButtonActionListener(int buttonIndex)
protected Container
createButtonArea()
Creates and returns a Container containing the buttons.protected LayoutManager
createLayoutManager()
protected Container
createMessageArea()
Messaged from installComponents to create a Container containing the body of the message.protected PropertyChangeListener
createPropertyChangeListener()
protected Container
createSeparator()
static ComponentUI
createUI(JComponent x)
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 fromgetDefaultIcon
.protected Icon
getIconForType(int messageType)
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(JComponent c)
Ifc
is theJOptionPane
the receiver is contained in, the preferred size that is returned is the maximum of the preferred size of theLayoutManager
for theJOptionPane
, andgetMinimumOptionPaneSize
.protected boolean
getSizeButtonsToSameWidth()
Returns true, basic L&F wants all the buttons to have the same width.protected void
installComponents()
protected void
installDefaults()
protected void
installKeyboardActions()
protected void
installListeners()
void
installUI(JComponent c)
Installs the receiver as the L&F for the passed inJOptionPane
.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(JOptionPane op)
If inputComponent is non-null, the focus is requested on that, otherwise request focus on the default valueprotected void
uninstallComponents()
protected void
uninstallDefaults()
protected void
uninstallKeyboardActions()
protected void
uninstallListeners()
void
uninstallUI(JComponent c)
Removes the receiver from the L&F controller of the passed in split pane.-
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, paint, update
-
-
-
-
Field Detail
-
MinimumWidth
public static final int MinimumWidth
- See Also:
- Constant Field Values
-
MinimumHeight
public static final int MinimumHeight
- See Also:
- Constant Field Values
-
optionPane
protected JOptionPane optionPane
JOptionPane
that the receiver is providing the look and feel for.
-
minimumSize
protected Dimension minimumSize
-
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
-
-
Method Detail
-
createUI
public static ComponentUI createUI(JComponent x)
Creates a new BasicOptionPaneUI instance.
-
installUI
public void installUI(JComponent c)
Installs the receiver as the L&F for the passed inJOptionPane
.- Overrides:
installUI
in classComponentUI
- Parameters:
c
- the component where this UI delegate is being installed- See Also:
ComponentUI.uninstallUI(javax.swing.JComponent)
,JComponent.setUI(javax.swing.plaf.ComponentUI)
,JComponent.updateUI()
-
uninstallUI
public void uninstallUI(JComponent c)
Removes the receiver from the L&F controller of the passed in split pane.- Overrides:
uninstallUI
in 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:
ComponentUI.installUI(javax.swing.JComponent)
,JComponent.updateUI()
-
installDefaults
protected void installDefaults()
-
uninstallDefaults
protected void uninstallDefaults()
-
installComponents
protected void installComponents()
-
uninstallComponents
protected void uninstallComponents()
-
createLayoutManager
protected LayoutManager createLayoutManager()
-
installListeners
protected void installListeners()
-
uninstallListeners
protected void uninstallListeners()
-
createPropertyChangeListener
protected PropertyChangeListener createPropertyChangeListener()
-
installKeyboardActions
protected void installKeyboardActions()
-
uninstallKeyboardActions
protected void uninstallKeyboardActions()
-
getMinimumOptionPaneSize
public Dimension getMinimumOptionPaneSize()
Returns the minimum size the option pane should be. Primarily provided for subclassers wishing to offer a different minimum size.
-
getPreferredSize
public Dimension getPreferredSize(JComponent c)
Ifc
is theJOptionPane
the receiver is contained in, the preferred size that is returned is the maximum of the preferred size of theLayoutManager
for theJOptionPane
, andgetMinimumOptionPaneSize
.- Overrides:
getPreferredSize
in 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- See Also:
JComponent.getPreferredSize()
,LayoutManager.preferredLayoutSize(java.awt.Container)
-
createMessageArea
protected Container createMessageArea()
Messaged from installComponents to create a Container containing the body of the message. The icon is the created by callingaddIcon
.
-
addMessageComponents
protected void addMessageComponents(Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated)
Creates the appropriate object to representmsg
and places it intocontainer
. Ifmsg
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, ifd
is an Object[], this method will be recursively invoked for the children.internallyCreated
is true if Objc is an instance of Component and was created internally by this method (this is used to correctly set hasCustomComponents only if !internallyCreated).
-
getMessage
protected Object getMessage()
Returns the message to display from the JOptionPane the receiver is providing the look and feel for.
-
addIcon
protected void addIcon(Container top)
Creates and adds a JLabel representing the icon returned fromgetIcon
totop
. This is messaged fromcreateMessageArea
-
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 fromgetDefaultIcon
.
-
getIconForType
protected Icon getIconForType(int messageType)
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)
Recursively creates new JLabel instances to representd
. Each JLabel instance is added toc
.
-
createSeparator
protected Container createSeparator()
-
createButtonArea
protected Container createButtonArea()
Creates and returns a Container containing the buttons. The buttons are created by callinggetButtons
.
-
addButtonComponents
protected void addButtonComponents(Container container, Object[] buttons, int initialIndex)
Creates the appropriate object to represent each of the objects inbuttons
and adds it tocontainer
. This differs from addMessageComponents in that it will recurse onbuttons
and that if button is not a Component it will create an instance of JButton.
-
createButtonActionListener
protected ActionListener createButtonActionListener(int buttonIndex)
-
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.
-
getSizeButtonsToSameWidth
protected boolean getSizeButtonsToSameWidth()
Returns true, basic L&F wants all the buttons to 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.
-
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 classOptionPaneUI
-
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 classOptionPaneUI
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/12/2024 15:20:40 Cette version de la page est en cache (à la date du 22/12/2024 15:20:40) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 02/10/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/plaf/basic/basicoptionpaneui.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.