Java popup trigger in Linux

和自甴很熟 提交于 2019-12-08 15:55:42

问题


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
}

回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/5736872/java-popup-trigger-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!