Synth 的 JPanel 状态
在我的应用程序中,我有一些自定义按钮,它们具有自定义文本/图标布局和一些通常不与按钮关联的额外元素。例如,有些有 2 个文本标签,而不是 1 个。
我已经实现了我的自定义按钮,如下所示:
class CustomButton extends JPanel implements MouseListener {
CustomButton() {
setName("CustomButton");
}
}
我使用 Synth 作为 L&F,并且我希望拥有尽可能多的样式信息(主要是在 XML 文件中定义的颜色设置)。
在 XML 文件中,我有这样的内容:
<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”。
我的问题是,如何通知 Synth 我的自定义按钮的状态?
顺便说一句:我确实考虑过让 CustomButton
扩展 JButton
但我无法找到一个好的方法来制作带有自定义子组件的按钮。如果这种方法不起作用,我可能会将其作为一个单独的问题发布。
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");
}
}
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).
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" />
When I run the app, color 'A' is used correctly, but colors 'B' and 'C' are never set.
My question is, how can I notify Synth about the state of my custom button?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许不是您问题的答案,我认为使用 ButtonModel,如 MouseListener 和 MouseMotionListener,示例因为我的想法是此处,
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,