你只要加个MouseListener不就可以了!判断MouseEvent的getModifiers()是BUTTON1_MASK(左键),还是BUTTON3_MASK(右键)。MouseEvent e; (e.getModifiers()==e.META_MASK)也可以表示右键see this: MouseEvent extends InputEvent and these defines in InputEvent: /** * The mouse button1 modifier constant. */ public static final int BUTTON1_MASK = 1 << 4; /** * The mouse button2 modifier constant. */ public static final int BUTTON2_MASK = Event.ALT_MASK; /** * The mouse button3 modifier constant. */ public static final int BUTTON3_MASK = Event.META_MASK; /** * The meta key modifier constant. */ public static final int META_MASK = Event.META_MASK;
(e.getModifiers()==e.META_MASK)也可以表示右键see this: MouseEvent extends InputEvent
and these defines in InputEvent:
/**
* The mouse button1 modifier constant.
*/
public static final int BUTTON1_MASK = 1 << 4; /**
* The mouse button2 modifier constant.
*/
public static final int BUTTON2_MASK = Event.ALT_MASK; /**
* The mouse button3 modifier constant.
*/
public static final int BUTTON3_MASK = Event.META_MASK;
/**
* The meta key modifier constant.
*/
public static final int META_MASK = Event.META_MASK;
SwingUtilities.isMiddleMouseButton(MouseEvent e)