Swing Synth 皮肤:你可以覆盖样式吗?
我为 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 选择锚定到“标签”的样式区域并将其应用于样式表中的所有标签。
以下摘自 Synth 上有限的 Java 文档,表明可以混合应用于区域和名称的样式,并且它们的值将被合并:
您可以绑定到个人,命名为 组件,无论它们是否 也绑定为区域。例如, 假设你想要“OK”并且 GUI 中的“取消”按钮已处理 与其他所有不同 按钮。首先,你会给出“OK” 和取消按钮名称,使用 component.setName() 方法。然后你 将定义三种样式:一种用于 一般按钮(区域 = “按钮”),一个为“确定”按钮(名称 =“确定”),还有一个用于“取消”按钮(名称 =“取消”)。最后,你会 像这样绑定这些样式:
<bind style="styleButton" type="region" key="Button">
<bind style="styleOK" type="name" key="OK">
<bind style="styleCancel" type="name" key="Cancel">
当组件或区域绑定到 不止一种风格,这些风格是 合并
注意:正如样式可以绑定到 多个地区或名称、多个 样式可以绑定到一个区域或 姓名。这些多种风格被合并 用于区域或名称。优先级是 赋予稍后定义的样式 文件
,第一个样式中的定义似乎不能被第二个样式中的定义覆盖?
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
mergedNote: 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以确认不可能覆盖以前使用的锚定类型(也就是说,您不能在区域键上设置 type="BACKGROUND" 颜色,然后在区域键上设置不同的 type="BACKGROUND" 颜色设置不同的类型,例如 TEXT_BACKGROUND 可以,因为 Synth 将两种样式合并为一个,但是,您无法在第二种样式中再次设置它
。但是,我们找到了一种解决方法,在 catch-all、key=".*" 样式中设置一组“默认”颜色,并在名称锚定样式中偏离这些颜色:
和
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:
and