So I have two buttons,
JButton playB = new JButton(new ImageIcon("res/playA.png"));
playB.setBorder(BorderFactory.createEmptyBorder());
playB.setContentAreaFilled(false);
JButton playA = new JButton(new ImageIcon("res/playA.png"));
playA.setBorder(BorderFactory.createEmptyBorder());
playA.setContentAreaFilled(false);
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.
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 with ActionListener
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 from Mouse
or KeyEvent
s, because both those event will witch that (immediatelly) to roll_over
,
then there is only one way, call programatically JButton.doClick()
from KeyBinding
s, but still is there question when, how and for why reason ... complicating simple things