Composing Swing Components: How do I add the ability to add ActionListeners?
I’d use a JToggelButton, as shown here, or delegate to the contained buttons, as @duffymo suggests. If you really need a custom OnOffSwitchEvent, the standard wiring is outlined in EventListenerList, an instance of which is contained in every JComponent. Addendum: Here’s an example of delegating to a ButtonGroup containing two buttons. The label is decorated … Read more