在我的应用程序中,我有一些自定义按钮,它们有自定义的文本/图标布局,以及一些通常不与按钮关联的额外元素。例如,有些有两个文本标签,而不是一个。
我实现了我的自定义按钮,如下所示:
class CustomButton extends JPanel implements MouseListener {
CustomButton() {
setName("CustomButton");
}
}我对L&F使用Synth,我希望在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,但我想不出一个好方法来制作一个带有自定义子组件的按钮。如果这种方法不起作用,我可能会把它作为一个单独的问题发布。
发布于 2011-10-14 22:44:42
也许不是你问题的答案,我认为使用ButtonModel更合适,比如MouseListener和MouseMotionListener,我的想法是here,
https://stackoverflow.com/questions/7768889
复制相似问题