1

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.

vaughandroid
  • 4,315
  • 1
  • 27
  • 33

1 Answers1

2

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,

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Yeah, I actually have a `DefaultButtonModel` instance that I'm using internally to set the state of in the `MouseListener` methods. I'm hoping I can just hook that up to a listener in one of the Swing UI classes. – vaughandroid Oct 14 '11 at 15:09
  • ButtonModel implements internally required Events from Mouse and KeyBoards, then there no needed implements MouseListener twice, – mKorbel Oct 14 '11 at 16:26
  • From what I can tell, the `ButtonModel` only deals with mouse & keyboard events once it's added to a button using using `AbstractButton.setModel()` - `DefaultButtonModel` doesn't implement `MouseListener`. Since I've extended a `JPanel` I'm having to initiate the state changes that are normally triggered by `AbstractButton`. – vaughandroid Oct 17 '11 at 08:33
  • not sure, dis_agreed, but back to the Synt maybe this thread http://stackoverflow.com/questions/6992633/painting-the-slider-icon-of-jslider/6992829#6992829 can help you with, (sure) I'm not like this L&F – mKorbel Oct 17 '11 at 08:53