I am trying to change the mouse button to pan the map view from the right button to left.
There is a simple code changing the button after the left mouse button has been clicked:
public class Map extends JMapViewer {
public Map() {
new DefaultMapController(this){
public void mousePressed(MouseEvent e) {
this.setMovementMouseButton(MouseEvent.BUTTON1);
}
};
}
}
Main class:
public class JMapViewerDemo {
public static void main(String[] args) {
JFrame f = new JFrame();
f.add(new Map());
f.setSize(800, 600);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Surprisingly, the code does not work (no reassignment has been done). Why? However, after calling the parent class method
public void mousePressed(MouseEvent e) {
super.mousePressed(e); //Calling the parent-class method
this.setMovementMouseButton(MouseEvent.BUTTON1);
}
the following behavior was observed:
Click the left mouse button. When dragging no reassignment has been done (the same situation).
Release the left mouse button.
Click the left mouse button again. When dragging, the panning is assign to the left mouse button.
I find this behavior strange. Maybe, I am using this method incorrectly...
How to change the panning button directly, without being released and clicked again? Thanks for your help...