Pseudoclass

From JAXXWiki

In CSS, a pseudoclass is a logical group to which a component belongs only when it is in certain states. For instance, components only belong to the :focused pseudoclass when they currently have focus. Unlike other CSS selectors, pseudoclasses are inherently dynamic: a component's ID or class cannot change while a program is running, but it may change pseudoclasses many times over the course of a run.

Supported pseudoclasses

JAXX supports a number of different pseudoclasses:

PseudoclassDescription
:enabled Applies when the component is enabled
:disabled Applies when the component is disabled
:focused Applies when the component is focused
:unfocused Applies when the component not focused
:mouseover Applies when the mouse is over the component
:mouseout Applies when the mouse is not over the component
:mouseup Applies when the mouse is pressed on the component
:mousedown Applies when the mouse is not pressed on the component
:selected Applies when component's isSelected() method returns true
:unselected Applies when component's isSelected() method returns false

It is not an error for multiple pseudoclasses to apply to a component at once. Conflicting properties specified by multiple pseudoclass rules are handled according to normal CSS prioritization.

Programmatic pseudoclasses

In addition to these predefined types, JAXX supports programmatic pseudoclasses. A programmatic pseudoclass is an arbitrary true/false Java expression, escaped by curly braces, which decides whether the rule applies.

JSlider.dangerZone:{object.getValue() > DANGER_LEVEL} {
    background: red;
}

This causes all JSliders with the attribute styleClass="danger" to turn red when their values exceed DANGER_LEVEL. Within a programmatic pseudoclass, the name "object" refers to the component currently being examined; in other words, object takes on the value of each slider.

Most of the predefined pseudoclasses are actually implemented in terms of programmatic pseudoclasses. The :focused pseudoclass, for instance, is exactly equivalent to :{object.hasFocus()}. Programmatic pseudoclasses are themselves implemented in terms of the data binding system, and can track the value of any expression that data binding can track.

Example

Example of a CSS pseudoclass:

<Application title='Pseudoclass Demo'>
  <style>
    AbstractButton:mouseover {
        foreground:red;
    }
  </style>

  <VBox margin='12'>
    <JButton label='JButton'/>
    <JCheckBox label='JCheckBox'/>
    <JRadioButton label='JRadioButton'/>
  </VBox>
</Application>

Note the CSS rule for AbstractButton:mouseover. This will cause all subclasses of AbstractButton to turn red when moused over. Here is what it looks like in action:

Image:Pseudoclass-animation.gif