Workaround for some operating systems where java.awt.event.MouseEvent#isPopupTrigger() does not return true if the user clicked down the right mouse button. - Java Swing

Java examples for Swing:Mouse Event

Description

Workaround for some operating systems where java.awt.event.MouseEvent#isPopupTrigger() does not return true if the user clicked down the right mouse button.

Demo Code


//package com.java2s;
import java.awt.event.MouseEvent;

public class Main {
    /**/*  w w w .  ja v  a 2  s  .  c  o m*/
     * Workaround for some operating systems where
     * {@code java.awt.event.MouseEvent#isPopupTrigger()} does not return true
     * if the user clicked down the right mouse button.
     *
     * @param  evt  mouse event
     * @return true if the right mouse button is down
     */
    public static boolean isPopupTrigger(MouseEvent evt) {
        if (evt == null) {
            throw new NullPointerException("evt == null");
        }

        return evt.isPopupTrigger() || (evt.getModifiers() == 4);
    }
}

Related Tutorials