Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java popup trigger in Linux

Tags:

java

linux

popup

I have an application in which you can do a right mouse button press and drag (as well as a left press and drag for different operations). However, when running this on linux, it seems that popup menus are triggered by a mousePressed and not a mouseReleased. This is resulting in every time I press the right mouse button to perform a drag, the popup menus are triggered (unlike windows, where it is mouseReleased).

Any thoughts on how to work around this?

thanks.

EDIT: Posting code

Code for popup menu

// this is called from mousePressed and mouseReleased
if (e.isPopupTrigger() && !e.isConsumed()) {
    // show the popup menu
}

This code is what is called on the right mouse press/drag (this is 3rd party code, but it is open source so I can change as needed)

// this is called on all mouse events
if (buttonAction.mouseButton != 0)
{
    // handle the event
}
like image 297
Jeff Storey Avatar asked Apr 20 '11 21:04

Jeff Storey


2 Answers

I think the correct procedure in your case should be to unify where and when to show the popup. As a drag event, if exist, follows a press event you should avoid writting logic for showing the popup in the press event (and then also write logic in the press event for showing the popup). Some users feel good navigating the popup while holding the popup button, and some other users just don't care or don't know. But in your case, you won't be able to navigate the popup menu while dragging without adding extra code.

My way would we to manage the logic to always show the popup on the release event. Entering a release event after a drag should be enough information to know that the popup shouldn't be visible. And of course, always if you can change and modify the source.

like image 101
Sebastian Avatar answered Oct 02 '22 08:10

Sebastian


Yes, use isPopupTrigger(), as shown here.

Addendum:

it appears isPopupTrigger is triggered on mousePressed in linux.

Yes, it's the same on Mac OS X. You have to call isPopupTrigger() from both mousePressed() and mouseReleased(). There's a related example in GraphPanel.

like image 44
trashgod Avatar answered Oct 02 '22 08:10

trashgod