- java.lang.Object
-
- javax.swing.plaf.synth.SynthStyle
-
- javax.swing.plaf.nimbus.NimbusStyle
-
public final class NimbusStyle extends SynthStyle
A SynthStyle implementation used by Nimbus. Each Region that has been registered with the NimbusLookAndFeel will have an associated NimbusStyle. Third party components that are registered with the NimbusLookAndFeel will therefore be handed a NimbusStyle from the look and feel from the #getStyle(JComponent, Region) method.
This class properly reads and retrieves values placed in the UIDefaults according to the standard Nimbus naming conventions. It will create and retrieve painters, fonts, colors, and other data stored there.
NimbusStyle also supports the ability to override settings on a per component basis. NimbusStyle checks the component's client property map for "Nimbus.Overrides". If the value associated with this key is an instance of UIDefaults, then the values in that defaults table will override the standard Nimbus defaults in UIManager, but for that component instance only.
Optionally, you may specify the client property "Nimbus.Overrides.InheritDefaults". If true, this client property indicates that the defaults located in UIManager should first be read, and then replaced with defaults located in the component client properties. If false, then only the defaults located in the component client property map will be used. If not specified, it is assumed to be true.
You must specify "Nimbus.Overrides" for "Nimbus.Overrides.InheritDefaults" to have any effect. "Nimbus.Overrides" indicates whether there are any overrides, while "Nimbus.Overrides.InheritDefaults" indicates whether those overrides should first be initialized with the defaults from UIManager.
The NimbusStyle is reloaded whenever a property change event is fired for a component for "Nimbus.Overrides" or "Nimbus.Overrides.InheritDefaults". So for example, setting a new UIDefaults on a component would cause the style to be reloaded.
The values are only read out of UIManager once, and then cached. If you need to read the values again (for example, if the UI is being reloaded), then discard this NimbusStyle and read a new one from NimbusLookAndFeel using NimbusLookAndFeel.getStyle.
The primary API of interest in this class for 3rd party component authors are the three methods which retrieve painters: #getBackgroundPainter, #getForegroundPainter, and #getBorderPainter.
NimbusStyle allows you to specify custom states, or modify the order of states. Synth (and thus Nimbus) has the concept of a "state". For example, a JButton might be in the "MOUSE_OVER" state, or the "ENABLED" state, or the "DISABLED" state. These are all "standard" states which are defined in synth, and which apply to all synth Regions.
Sometimes, however, you need to have a custom state. For example, you want JButton to render differently if it's parent is a JToolbar. In Nimbus, you specify these custom states by including a special key in UIDefaults. The following UIDefaults entries define three states for this button:
JButton.States = Enabled, Disabled, Toolbar JButton[Enabled].backgroundPainter = somePainter JButton[Disabled].background = BLUE JButton[Toolbar].backgroundPainter = someOtherPaint
As you can see, the
JButton.States
entry lists the states that the JButton style will support. You then specify the settings for each state. If you do not specify theJButton.States
entry, then the standard Synth states will be assumed. If you specify the entry but the list of states is empty or null, then the standard synth states will be assumed.
-
-
Field Summary
Fields Modifier and Type Field and Description static String
LARGE_KEY
static double
LARGE_SCALE
static String
MINI_KEY
static double
MINI_SCALE
static String
SMALL_KEY
static double
SMALL_SCALE
-
Method Summary
Methods Modifier and Type Method and Description Object
get(SynthContext ctx, Object key)
Getter for a region specific style property.Painter
getBackgroundPainter(SynthContext ctx)
Gets the appropriate background Painter, if there is one, for the state specified in the given SynthContext.Painter
getBorderPainter(SynthContext ctx)
Gets the appropriate border Painter, if there is one, for the state specified in the given SynthContext.protected Color
getColorForState(SynthContext ctx, ColorType type)
Returns the color for the specified state.protected Font
getFontForState(SynthContext ctx)
Returns the font for the specified state.Painter
getForegroundPainter(SynthContext ctx)
Gets the appropriate foreground Painter, if there is one, for the state specified in the given SynthContext.Insets
getInsets(SynthContext ctx, Insets in)
Returns the Insets that are used to calculate sizing information.SynthPainter
getPainter(SynthContext ctx)
Returns theSynthPainter
that will be used for painting.void
installDefaults(SynthContext ctx)
Installs the necessary state from this Style on theJComponent
fromcontext
.boolean
isOpaque(SynthContext ctx)
Returns true if the region is opaque.-
Methods inherited from class javax.swing.plaf.synth.SynthStyle
getBoolean, getColor, getFont, getGraphicsUtils, getIcon, getInt, getString, uninstallDefaults
-
-
-
-
Field Detail
-
LARGE_KEY
public static final String LARGE_KEY
- See Also:
- Constant Field Values
-
SMALL_KEY
public static final String SMALL_KEY
- See Also:
- Constant Field Values
-
MINI_KEY
public static final String MINI_KEY
- See Also:
- Constant Field Values
-
LARGE_SCALE
public static final double LARGE_SCALE
- See Also:
- Constant Field Values
-
SMALL_SCALE
public static final double SMALL_SCALE
- See Also:
- Constant Field Values
-
MINI_SCALE
public static final double MINI_SCALE
- See Also:
- Constant Field Values
-
-
Method Detail
-
installDefaults
public void installDefaults(SynthContext ctx)
Description copied from class:SynthStyle
Installs the necessary state from this Style on theJComponent
fromcontext
.- Overrides:
installDefaults
in classSynthStyle
- Parameters:
ctx
- SynthContext identifying component to install properties to.
-
getInsets
public Insets getInsets(SynthContext ctx, Insets in)
Description copied from class:SynthStyle
Returns the Insets that are used to calculate sizing information.- Overrides:
getInsets
in classSynthStyle
- Parameters:
ctx
- SynthContext identifying requesterin
- Insets to place return value in.- Returns:
- Sizing Insets.
-
getColorForState
protected Color getColorForState(SynthContext ctx, ColorType type)
Description copied from class:SynthStyle
Returns the color for the specified state. This should NOT call any methods on theJComponent
.- Specified by:
getColorForState
in classSynthStyle
- Parameters:
ctx
- SynthContext identifying requestertype
- Type of color being requested.- Returns:
- Color to render with
-
getFontForState
protected Font getFontForState(SynthContext ctx)
Description copied from class:SynthStyle
Returns the font for the specified state. This should NOT call any method on theJComponent
.- Specified by:
getFontForState
in classSynthStyle
- Parameters:
ctx
- SynthContext identifying requester- Returns:
- Font to render with
-
getPainter
public SynthPainter getPainter(SynthContext ctx)
Description copied from class:SynthStyle
Returns theSynthPainter
that will be used for painting. This may return null.- Overrides:
getPainter
in classSynthStyle
- Parameters:
ctx
- SynthContext identifying requester- Returns:
- SynthPainter to use
-
isOpaque
public boolean isOpaque(SynthContext ctx)
Description copied from class:SynthStyle
Returns true if the region is opaque.- Overrides:
isOpaque
in classSynthStyle
- Parameters:
ctx
- SynthContext identifying requester- Returns:
- true if region is opaque.
-
get
public Object get(SynthContext ctx, Object key)
Description copied from class:SynthStyle
Getter for a region specific style property.- Overrides:
get
in classSynthStyle
- Parameters:
ctx
-key
- must not be null- Returns:
- Value of the named property
-
getBackgroundPainter
public Painter getBackgroundPainter(SynthContext ctx)
Gets the appropriate background Painter, if there is one, for the state specified in the given SynthContext. This method does appropriate fallback searching, as described in #get.- Parameters:
ctx
- The SynthContext. Must not be null.- Returns:
- The background painter associated for the given state, or null if none could be found.
-
getForegroundPainter
public Painter getForegroundPainter(SynthContext ctx)
Gets the appropriate foreground Painter, if there is one, for the state specified in the given SynthContext. This method does appropriate fallback searching, as described in #get.- Parameters:
ctx
- The SynthContext. Must not be null.- Returns:
- The foreground painter associated for the given state, or null if none could be found.
-
getBorderPainter
public Painter getBorderPainter(SynthContext ctx)
Gets the appropriate border Painter, if there is one, for the state specified in the given SynthContext. This method does appropriate fallback searching, as described in #get.- Parameters:
ctx
- The SynthContext. Must not be null.- Returns:
- The border painter associated for the given state, or null if none could be found.
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/swing/plaf/nimbus/NimbusStyle.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.