开发者

How to make a mouseEvent from a Component to be recognized in a subcomponent?

I have a JTabPane, and i have added a MoustListener to it(for tab's title). When i press right click, a popup menu is created. i need to make it invisible when i press the mouse button in any place of window. how can i do this??

(the MouseListener is applied only for ta开发者_JAVA百科b's title.)


i need to make it invisible when i press the mouse button in any place of window. how can i do this??

This is the default behavour of a JPopupMenu so you don't have to do anything special.

Read the JPopupMenu API and you will find a link to the Swing tutorial on "How to Use Menus". The tutorial contains a working example of using a popup menu. Compare your code with the tutorial to see whats different. We can't help you because we don't know what your code is like.

If you need more help post your SSCCE.


in the good old days what I did to solve this problem was to register a mouse listener with ALL the components. you can write a fairly simple function that recursively traverses a top level container and do it.

this was with Java 1.1, so maybe there is a better option today.


One way off the top of my head would be to grab the coordinates of the clicks, and then have another method to determine if the clicks are on the tab, or inside of the content area of the tabs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜