Note that there are some explanatory texts on larger screens.

plurals
  1. POSwing Synth Skin: Can you override Styles?
    text
    copied!<p>I have a style defined for a JLabel:</p> <pre><code>&lt;style id="myLabel"&gt; &lt;state&gt; &lt;opaque value="true"/&gt; &lt;color value="blue" type="BACKGROUND"/&gt; &lt;color value="red" type="FOREGROUND"/&gt; &lt;/state&gt; &lt;/style&gt; &lt;bind style="myLabel" type="region" key="label"/&gt; </code></pre> <p>However, I want certain JLabels (in certain JPanels) to be styled completely differently:</p> <pre><code>&lt;style id="myUnrelatedPanel"&gt; &lt;state&gt; &lt;opaque value="true"/&gt; &lt;color value="green" type="BACKGROUND"/&gt; &lt;color value="yellow" type="FOREGROUND"/&gt; &lt;/state&gt; &lt;/style&gt; &lt;bind style="myLabel" type="name" key="_valueOfMyPanel.getName()_in_here"/&gt; </code></pre> <p>The above does not work, because the style for the JLabel is being enforced.</p> <p>Nesting styles does not appear to work. The compiler does not complain; Synth picks up the style region-anchored to 'label' and applies it to all labels within the stylesheet.</p> <p>The following extract from the limited Java documentation on Synth suggests that it is possible to mix styles applied to Regions and Names, and that their values will be merged:</p> <blockquote> <p>You can bind to individual, named components, whether or not they are also bound as regions. For example, suppose you want to have the "OK" and "Cancel" buttons in your GUI treated differently than all the other buttons. First, you would give the OK and Cancel buttons names, using the component.setName() method. Then, you would define three styles: one for buttons in general (region = "Button"), one for the OK button (name = "OK"), and one for the Cancel button (name = "Cancel"). Finally, you would bind these styles like this:</p> </blockquote> <pre><code> &lt;bind style="styleButton" type="region" key="Button"&gt; &lt;bind style="styleOK" type="name" key="OK"&gt; &lt;bind style="styleCancel" type="name" key="Cancel"&gt; </code></pre> <blockquote> <p>When a component or region is bound to more than one style, the styles are merged</p> <p>Note: Just as a style can be bound to multiple regions or names, multiple styles can be bound to a region or name. These multiple styles are merged for the region or name. Precedence is given to styles defined later in the file</p> </blockquote> <p>However, it does not appear that a defined in the first Style can be overrided by a defined in the second style? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload