开发者

Java popup trigger in Linux

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
}


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.


MouseEvent.isPopupTrigger(). Returns whether or not this mouse event is the popup menu trigger event for the platform.

edit - : You need to make the check in both mousePressed for linux, and mouseReleased for windows.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜