Synth 的 JPanel 状态

发布于 2024-12-09 14:37:17 字数 1014 浏览 0 评论 0原文

在我的应用程序中,我有一些自定义按钮,它们具有自定义文本/图标布局和一些通常不与按钮关联的额外元素。例如,有些有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌辣 2024-12-16 14:37:17

也许不是您问题的答案,我认为使用 ButtonModel,如 MouseListenerMouseMotionListener,示例因为我的想法是此处

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,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文