开发者

JPanel states for Synth

开发者 https://www.devze.com 2023-04-12 20:54 出处:网络
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.

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 idre开发者_StackOverflow中文版f="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.


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,

0

精彩评论

暂无评论...
验证码 换一张
取 消