JPanel states for Synth

550 views Asked by At

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.

1

There are 1 answers

4
mKorbel On

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,