How would I create it so that when I move my mouse over button A it switches to button B? All I can think of doing is using a mouse listener but I'm wondering if there would be any better way.
Note: The setRolloverIcon method can't be used for this.
this idea, switching with two JButtons isn't ..., nor to use MouseListener, because all mouse and key events are implemented in JButtons APi and correctly
use JButton.setRolloverIcon with event from ButtonModel, output should be two Swing Actions instead of two
JButton
s added on runtime, and withActionListener
s
e.g.
JButton.getModel().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
ButtonModel model = (ButtonModel) e.getSource();
if (model.isRollover()) {
//doSomething
} else if (model.isPressed()) {
//doSomething
} // etc
}
});
EDIT
again back
How would I create it so that when I move my mouse over button A it switches to button B? All I can think of doing is using a mouse listener but I'm wondering if there would be any better way.
conclusion then first
JButton (button A)
isn't, never will be accesible on users side fromMouse
orKeyEvent
s, because both those event will witch that (immediatelly) toroll_over
,then there is only one way, call programatically
JButton.doClick()
fromKeyBinding
s, but still is there question when, how and for why reason ... complicating simple things