Swing Synth Skin:你可以覆盖样式吗?(Swing Synth Skin: Can you override Styles?)

编程入门 行业动态 更新时间:2024-10-28 02:35:14
Swing Synth Skin:你可以覆盖样式吗?(Swing Synth Skin: Can you override Styles?)

我有一个为JLabel定义的样式:

<style id="myLabel"> <state> <opaque value="true"/> <color value="blue" type="BACKGROUND"/> <color value="red" type="FOREGROUND"/> </state> </style> <bind style="myLabel" type="region" key="label"/>

但是,我希望某些JLabel(在某些JPanel中)的样式完全不同:

<style id="myUnrelatedPanel"> <state> <opaque value="true"/> <color value="green" type="BACKGROUND"/> <color value="yellow" type="FOREGROUND"/> </state> </style> <bind style="myLabel" type="name" key="_valueOfMyPanel.getName()_in_here"/>

上述方法不起作用,因为JLabel的样式正在执行。

嵌套样式似乎不起作用。 编译器没有抱怨; Synth选择样式区域 - 锚定到'label'并将其应用于样式表中的所有标签。

以下来自Synth的有限Java文档的摘录表明,可以混合应用于区域和名称的样式,并且它们的值将被合并:

您可以绑定到各个命名组件,无论它们是否也绑定为区域。 例如,假设您希望GUI中的“确定”和“取消”按钮与所有其他按钮的处理方式不同。 首先,您将使用component.setName()方法给出“确定”和“取消”按钮名称。 然后,您将定义三种样式:一种用于一般按钮(region =“Button”),一种用于OK按钮(name =“OK”),另一种用于Cancel按钮(name =“Cancel”)。 最后,您将绑定这些样式,如下所示:

<bind style="styleButton" type="region" key="Button"> <bind style="styleOK" type="name" key="OK"> <bind style="styleCancel" type="name" key="Cancel">

当组件或区域绑定到多个样式时,将合并样式

注意:正如样式可以绑定到多个区域或名称一样,可以将多个样式绑定到区域或名称。 这些多个样式将合并为区域或名称。 优先级被赋予文件中稍后定义的样式

但是,第一种Style中定义的内容似乎不会被第二种样式中的定义覆盖?

I have a style defined for a JLabel:

<style id="myLabel"> <state> <opaque value="true"/> <color value="blue" type="BACKGROUND"/> <color value="red" type="FOREGROUND"/> </state> </style> <bind style="myLabel" type="region" key="label"/>

However, I want certain JLabels (in certain JPanels) to be styled completely differently:

<style id="myUnrelatedPanel"> <state> <opaque value="true"/> <color value="green" type="BACKGROUND"/> <color value="yellow" type="FOREGROUND"/> </state> </style> <bind style="myLabel" type="name" key="_valueOfMyPanel.getName()_in_here"/>

The above does not work, because the style for the JLabel is being enforced.

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.

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:

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:

<bind style="styleButton" type="region" key="Button"> <bind style="styleOK" type="name" key="OK"> <bind style="styleCancel" type="name" key="Cancel">

When a component or region is bound to more than one style, the styles are merged

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

However, it does not appear that a defined in the first Style can be overrided by a defined in the second style?

最满意答案

我可以确认无法覆盖以前使用的锚定类型(也就是说,您不能在区域键上设置type =“BACKGROUND”颜色,然后在其上设置不同的type =“BACKGROUND”颜色由于Synth将两种样式合并为一种样式,因此设置不同的类型(例如TEXT_BACKGROUND)会起作用。因为在第一种样式中设置了BACKGROUND,所以不能在第二种样式中再次设置它。

非常失望。 不过,我找到了一个解决方法。 在catch-all,key =“。*”样式中设置一组“默认”颜色,并在名称锚定样式中偏离这些颜色:

<style id="backingStyle"> <state> <opaque value="false"/> <font name="Arial" size="12"/> <color value="black" type="BACKGROUND"/> <color value="white" type="FOREGROUND"/> </state> </style> <bind style="backingStyle" type="region" key=".*"/>

<style id="backingStyle"> <state> <opaque value="false"/> <font name="Verdana" size="12"/> <color value="blue" type="BACKGROUND"/> <color value="green" type="FOREGROUND"/> </state> </style> <bind style="backingStyle" type="name" key="nameOfMyPanel"/>

I can confirm that it is not possible to override previously used, anchored types (that is to say, you can't set a type="BACKGROUND" colour on a region key, and then set a different type="BACKGROUND" colour on a named key. Setting a different type, such as TEXT_BACKGROUND would work, as Synth merges the two styles into one. Because BACKGROUND was set in the first Style, however, you cannot set it again in the Second style.

Very disappointing. I've found a workaround, however. Set a 'default' set of colours in the catch-all, key=".*" style, and deviate from these colours in name-anchored styles:

<style id="backingStyle"> <state> <opaque value="false"/> <font name="Arial" size="12"/> <color value="black" type="BACKGROUND"/> <color value="white" type="FOREGROUND"/> </state> </style> <bind style="backingStyle" type="region" key=".*"/>

and

<style id="backingStyle"> <state> <opaque value="false"/> <font name="Verdana" size="12"/> <color value="blue" type="BACKGROUND"/> <color value="green" type="FOREGROUND"/> </state> </style> <bind style="backingStyle" type="name" key="nameOfMyPanel"/>

更多推荐

样式,style,styles,Synth,电脑培训,计算机培训,IT培训"/> <meta name="descrip

本文发布于:2023-08-07 20:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465706.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:你可以   样式   Synth   Swing   Skin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!