tags:

views:

45

answers:

4

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 tab's title.)

A: 

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.

Omry
A: 

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.

broschb
A: 

You can add custom components to the tabs, as shown in the section named Tabs With Custom Components of the tutorial How to Use Tabbed Panes. This allows each tab to manage mouse events individually.

trashgod
A: 

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.

camickr