Synth的JPanel状态 [英] JPanel states for Synth
问题描述
在我的应用程序中,我有一些自定义按钮,这些按钮具有自定义的文本/图标布局以及一些通常与按钮无关的额外元素.例如有些包含2个文本标签,而不是1个.
In my application I have some custom buttons which have custom text/icon layouts and some extra elements not normally associated with buttons. e.g. Some have 2 text labels instead of one.
我实现了自定义按钮,如下所示:
I've implemented my custom buttons as follows:
class CustomButton extends JPanel implements MouseListener {
CustomButton() {
setName("CustomButton");
}
}
我正在为L& F使用Synth,我希望在XML文件中定义尽可能多的样式信息(主要是颜色设置).
I'm using Synth for the L&F, and I would like to have as much of the style information as possible (primarily color settings) defined in the XML file).
在XML文件中,我有这个:
In the XML file I have this:
<style id="customButtonStyle">
<state>
<color idref="A" type="BACKGROUND" />
</state>
<state value="MOUSE_OVER">
<color idref="B" type="BACKGROUND" />
</state>
<state value="PRESSED">
<color idref="C" type="BACKGROUND" />
</state>
</style>
<bind sytle="customButtonStyle" type="name" key="CustomButton" />
我运行该应用程序时,正确使用了颜色"A",但从未设置颜色"B"和"C".
When I run the app, color 'A' is used correctly, but colors 'B' and 'C' are never set.
我的问题是,如何通知Synth我的自定义按钮的状态?
My question is, how can I notify Synth about the state of my custom button?
顺便说一句:我确实考虑过让CustomButton
扩展JButton
,但是我想不出一种制作带有自定义子组件的按钮的好方法.如果这种方法行不通,我可能会将其作为一个单独的问题发布.
An aside: I did look into having CustomButton
extend JButton
but I couldn't work out a good way to make a button with custom sub components. I might post that as a separate question if this approach doesn't work out.
推荐答案
maybe not the answer to your question, I consider that more confortable is usage of ButtonModel, as MouseListener and MouseMotionListener, example for my idea is here,
这篇关于Synth的JPanel状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!