Popup menu on tab components disables JTabbedPane mouse clicks

When I add a popup menu to the tab components, the underlying JTabbedPane doesn't respond to any mouse click. How can we solve this?
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class TabPopupDemo extends JFrame {
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JMenuItem jMenuItem1;
    private JPopupMenu jPopupMenu1;
    private JTabbedPane jTabbedPane1;
    public TabPopupDemo() {
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(400, 300);
        setLocationRelativeTo(null);
        jPopupMenu1 = new JPopupMenu();
        jMenuItem1 = new JMenuItem("jMenuItem1");
        jTabbedPane1 = new JTabbedPane();
        jLabel1 = new JLabel("jLabel1");
        jLabel2 = new JLabel("jLabel2");
        jPopupMenu1.add(jMenuItem1);
        jTabbedPane1.addTab(null, jLabel1);
        jTabbedPane1.addTab(null, jLabel2);
        getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
        int tabCount = jTabbedPane1.getTabCount();
        for (int i = 0; i < tabCount; i++) {
            JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
            jTabbedPane1.setTabComponentAt(i, jLabel);
            jLabel.setName(String.valueOf(i));
            jLabel.setComponentPopupMenu(jPopupMenu1);
        jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
            public void popupMenuCanceled(final PopupMenuEvent evt) {
            public void popupMenuWillBecomeInvisible(final PopupMenuEvent evt) {
            public void popupMenuWillBecomeVisible(final PopupMenuEvent evt) {
                JPopupMenu source = (JPopupMenu) evt.getSource();
                JLabel invoker = (JLabel) source.getInvoker();
                JLabel component = (JLabel) jTabbedPane1.getComponentAt(Integer.parseInt(invoker.getName()));
                jMenuItem1.setText(invoker.getText() + ":  " + component.getText());
    public static void main(final String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TabPopupDemo().setVisible(true);
}

I don't know what the best solution would be.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class TabPopupDemo2 extends JFrame {
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JMenuItem jMenuItem1;
  private JPopupMenu jPopupMenu1;
  private JTabbedPane jTabbedPane1;
  public TabPopupDemo2() {
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setSize(400, 300);
    setLocationRelativeTo(null);
    jPopupMenu1 = new JPopupMenu();
    jMenuItem1 = new JMenuItem("jMenuItem1");
    jTabbedPane1 = new JTabbedPane();
    jLabel1 = new JLabel("jLabel1");
    jLabel2 = new JLabel("jLabel2");
    jPopupMenu1.add(jMenuItem1);
    jTabbedPane1.addTab(null, jLabel1);
    jTabbedPane1.addTab(null, jLabel2);
    getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
    int tabCount = jTabbedPane1.getTabCount();
    TabMouseListener tml = new TabMouseListener(jTabbedPane1);
    for (int i = 0; i < tabCount; i++) {
      JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
      jTabbedPane1.setTabComponentAt(i, jLabel);
      jLabel.setName(String.valueOf(i));
      jLabel.addMouseListener(tml);
      jLabel.setComponentPopupMenu(jPopupMenu1);
    jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
      public void popupMenuCanceled(PopupMenuEvent evt) {}
      public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
      public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
        //JPopupMenu source = (JPopupMenu) e.getSource();
        //JLabel invoker = (JLabel) source.getInvoker();
        int index = jTabbedPane1.getSelectedIndex();
        JLabel invoker = (JLabel) jTabbedPane1.getTabComponentAt(index);
        JLabel component = (JLabel) jTabbedPane1.getComponentAt(index);
        jMenuItem1.setText(invoker.getText() + ":  " + component.getText());
  static class TabMouseListener extends MouseAdapter{
    private final JTabbedPane tp;
    TabMouseListener(JTabbedPane tabbedPane) {
      this.tp = tabbedPane;
    private void dispatchEvent(MouseEvent me) {
      JLabel l = (JLabel)me.getSource();
      tp.dispatchEvent(SwingUtilities.convertMouseEvent(l,me,tp));
    public void mouseClicked(MouseEvent me)  { dispatchEvent(me); }
    public void mouseEntered(MouseEvent me)  { dispatchEvent(me); }
    public void mouseExited(MouseEvent me)   { dispatchEvent(me); }
    public void mousePressed(MouseEvent me)  { dispatchEvent(me); }
    public void mouseReleased(MouseEvent me) { dispatchEvent(me); }
  public static void main(final String args[]) {
    EventQueue.invokeLater(new Runnable() {
      public void run() { new TabPopupDemo2().setVisible(true); }
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class TabPopupDemo3 extends JFrame {
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JMenuItem jMenuItem1;
  private JPopupMenu jPopupMenu1;
  private JTabbedPane jTabbedPane1;
  public TabPopupDemo3() {
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setSize(400, 300);
    setLocationRelativeTo(null);
    jPopupMenu1 = new JPopupMenu();
//     jPopupMenu1 = new JPopupMenu() {
//       public void show(Component c, int x, int y) {
//         int i = jTabbedPane1.indexAtLocation(x, y);
//         if(i>=0) {
//           JLabel tab = (JLabel) jTabbedPane1.getTabComponentAt(i);
//           JLabel component = (JLabel) jTabbedPane1.getComponentAt(i);
//           jMenuItem1.setText(tab.getText() + ":  " + component.getText());
//           super.show(c, x, y);
    jMenuItem1 = new JMenuItem("jMenuItem1");
    jTabbedPane1 = new JTabbedPane();
    jTabbedPane1.setComponentPopupMenu(jPopupMenu1);
    jLabel1 = new JLabel("jLabel1");
    jLabel2 = new JLabel("jLabel2");
    jPopupMenu1.add(jMenuItem1);
    jTabbedPane1.addTab(null, jLabel1);
    jTabbedPane1.addTab(null, jLabel2);
    getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
    int tabCount = jTabbedPane1.getTabCount();
    for (int i = 0; i < tabCount; i++) {
      JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
      jTabbedPane1.setTabComponentAt(i, jLabel);
      jLabel.setName(String.valueOf(i));
      //jLabel.setComponentPopupMenu(jPopupMenu1);
    jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
      public void popupMenuCanceled(final PopupMenuEvent evt) {}
      public void popupMenuWillBecomeInvisible(final PopupMenuEvent evt) {}
      public void popupMenuWillBecomeVisible(final PopupMenuEvent evt) {
        JPopupMenu source = (JPopupMenu) evt.getSource();
        int i = jTabbedPane1.getSelectedIndex();
        JLabel tab = (JLabel) jTabbedPane1.getTabComponentAt(i);
        JLabel component = (JLabel) jTabbedPane1.getComponentAt(i);
        if(tab.getMousePosition()!=null) {
          jMenuItem1.setText(tab.getText() + ":  " + component.getText());
        }else{
          jMenuItem1.setText("aaaaaaaaa");
  public static void main(final String args[]) {
    EventQueue.invokeLater(new Runnable() {
      public void run() { new TabPopupDemo3().setVisible(true); }
}

Similar Messages

  • Disable right mouse click and IE6 galleryimg on af:objectImage

    hi,
    Could anyone tell me how I can disable right mouse click and IE6 galleryimg on af:objectImage?

    Hi Jagannath,
    Try like this.. Double click on application -> go to parameters tab, in parameters give WDDISABLEUSERPERSONALIZATION and value 'X'. It will disable user settings, you get window when right click but no user settings available.
    check this for more help...
    http://help.sap.com/saphelp_nw70/helpdata/en/7b/fb57412df8091de10000000a155106/content.htm
    Thanks,
    Kris.

  • Is it possible to Disable Right Mouse click In WebDynpro Java Application??

    Dear Experts,
    Is it possible to Disable Right Mouse click In WebDynpro Java Application??
    If yes then kindly suggest how.
    Warm Regards,
    Upendra Agrawal

    What is the use-case?
    Armin

  • Get the tab page that the mouse clicked on using PLSQL

    Another canvas related question ...
    Is it possible to detect the tab page that the mouse clicked on
    from within a WHEN-MOUSE-DOUBLECLICKED trigger,
    SYSTEM.MOUSE_CANVAS returns the name of the tab canvas.
    However, I need the name of the tab page within the tab canvas
    thanks
    Scott

    resolved - thanks
    resolution notes follow:
    ========================
    I forgot to mention that I dont know the type of canvas at runtime,
    so the code needs to work for tab and non-tab canvases
    Unfortunately, calling TOPMOST_TAB_PAGE for a non-tab canvas results in an
    error that can only be suppressed using an ON-ERROR trigger
    (SYSTEM.MESSAGE_LEVEL wont supress it, nor will EXCEPTION)
    anyway, I resolved this via another related post that I raised today.
    "Determining canvas type using PLSQL"
    thanks anyway.

  • Disable reload of restored tabs. Disable reload when clicked.

    The question above may seem like two problems, but the issue is only one problem.
    I have session manager and I want to use the cache to load my tabs when restored. Right now I have it where once restored, all my tabs don't reload on startup. Instead they reload when clicked.
    Is there any way I can disable the reload portion when their clicked? I found no setting in session manager that disable this and I'm beginning to believe it's within firefox itself. I tried the tab mix restore option by disabling session manager and that also results in the same thing happening.

    Please help! This is a very annoying bug in the new firefox versions. I always had a lots of tab open and after restarted firefox they just loaded from the CACHE!
    This is very important because:
    - it's slow to wait for every tab to load when i click or all of them at startup, and in the 99% of the cases the page didn't changed, maybe just it's modified time since a php/asp page can change, but not the content, and the most importnat, that i didn't wanted to reload them.
    - if i have a lot of login protected page than as i start firefox after my login session is over then it will reload all my pages and i totally LOSE every information. I will have only 30 login page tab....
    I hope that there is a solution for that. Nowdays 1GB+ cache is not a problem so it can work with a lots of tabs. The only thing i can do now is to HIBERNATE my PC every time :( So actually i don't close firefox...
    If there is no settings now, please implement a very simple "hibernation" hidden settings. But i think it's a very common problem, not just mine.

  • Application wide popup menu for JTextComponent descendants

    Hi!
    I'm working on large project with reach Swing GUI and I got stuck with one small but wery annoing problem. I have to append simple popup menu to all text input fields (JTextComponent descendants) in whole application. I'm realy lazy to append mouse listener on each component, so I'm asking, is there any way to append "default" popup menu for all components. Please, don't answer about custom components instead of Swing plain JTextComponent descendants - it's worse to change classes for all fields then add mouse listener to them.
    As an example of what I want I could forward you to UIManager.put() method, which affects all properties of component behaviour thoughout application. I want to find same solution, maybe there any registry or smth. else in API.
    Than you in advice.

    You could always try extending something like MetalTextFieldUI so that it adds the listeners to the text field automatically. You'd then need to register that UI class with the UIManager at startup:
    public class MyTextFieldUI extends MetalTextFieldUI {
      protected void installListeners() {
        super.installListeners();
        // TODO - Install your listener here
      protected void uninstallListeners() {
        super.uninstallListeners();
        // TODO - Uninstall your listener here
    UIManager.put("TextFieldUI", MyTextFieldUI.class.getName());Personally, I think you're just being lazy... getting your components to extend a subclass of JTextField should be no trouble at all and will leave you with clearer code.
    Hope this helps.

  • Challenge popup menu,  css stylesheet and button in table component

    Hello, in my last post i put the code of an example of popup menu but the only thing that need to run was a cdata tag. But in the example i only can open and close the popup menu in the top and left location that previously set in the css stylesheet .
    1.- I need to create a popup menu that can be diplayed if i click on a button in a table component of creator
    2.- The menu must waits and let me select the opcion I choose with a click otherrewise
    3.- The menu must dissapear if i move the cursor mouse away of the menu,
    I really need somebody helps me faster as u can, and i apreciate ur help, tnks!

    The best thing to do would be to find an existing popup menu widget in a JavaScript library, like dojo (dojotoolkit.org). If you can't find an existing JavaScript widget that fulfills your needs, you can write your own. It won't be easy, but you can use Creator's Auto Complete Text Field's JavaScript as a model. If that is the case, look at both the JavaScript at http://sunapp2.whardy.com/AjaxSamples2/faces/static/META-INF/autocomplete/script.js and the HTML source of the page located at http://sunapp2.whardy.com/AjaxSamples2/faces/DemoAutoCompleteTextField.jsp which is a page that is part of the Creator AJAX component catalog (http://developers.sun.com/ajax/componentscatalog.jsp).

  • I can't navigate between tabs using a mouse click since I installed latest version of Firefox

    Running ver 30. which is fine, but I cannot switch between open tabs using a left mouse click on the tab I wish to activate, as I have been doing for years. Have to use Ctrl-Tab instead. Don't like this. This problem started with this version of FF.

    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem.
    *Switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance
    *Do NOT click the Reset button on the Safe Mode start window
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Disabling iebrowser or iecanvas mouse clicking

    How to disable the mouse click event on a iebrowser or iecanvas?

    >No Adobe software, including the Adobe Updater, is known to disable Windows Explorer.
    Please see this tech note: http://kb.adobe.com/selfservice/viewContent.do?externalId=kb408524
    See also this forum thread on the problems described in that tech note: http://www.adobeforums.com/webx/.59b77897/1
    I'm not pointing fingers. I'm not saying that CS4 doesn't work on Vista-64. It certainly had been working just fine for us for a couple of months, and everything but InDesign was continuing to work until we tried to fix InDesign. I haven't seen this particular problem mentioned anywhere else, so I posted the description of the problem and the solution in case it ever happens to anyone else.
    As for incompatibilities, certainly it's possible that there is a third-party catalyst. That doesn't mean that there isn't an incompatibility. The Windows Explorer issue definitely appears to have a third-party catalyst as it only seems to happen on Gateway and HP systems, and it seems to be related to some unusual system directory permissions.
    Matthew Laun has been very helpful in trying to "run this to ground", to find out what the problem is and how to fix it. Which is a whole lot more helpful than declaring that it's not an Adobe problem when Adobe software has an incompatibility with something else.
    And the tech support person got InDesign working for us again. Which is a while lot more helpful than declaring that it's not an Adobe problem when Adobe software has an incompatibility with something else.

  • Right mouse click on field

    Hi All,
    I'm looking for a way to add a menuitem to the popup menu that you get if you right click on a field on a form.
    (SBO 8.81)
    I don't need the exact code, but I don't now which objects to use for this.
    Can anyone help me?
    Tnx!
    Sebastiaan

    Hi,
    please check SDK sample 22 Right-Click, there is everything you need.
    First catch RightClickEvent, then create the menu entry when beforeAction = true, and when beforeAction = false you have to remove it again (otherwise you will receive an error when rightclicking again).
    Regards
    Sebastian

  • Ignoring mouse clicks

    Is there a way in Java to ignore a mouse click? Because when you turn the mouse pointer into a hourglass, you are still able to click where ever you want. How can I disable the mouse clicking?
    Thx

    Apologies - my explanation was a bit terse.
    You need to communicate with the EventProcessor so that it knows what state your application is in. You will only have one EventProcessor in your application so you can so this via a static context, so it might look something like:
    public class EventProcessor extends EventQueue
      static boolean wait_;
      public EventProcessor()
        Toolkit.getDefaultToolkit().getSystemEventQueue().push(this);
      static void setWait(boolean w)
        wait_ = w;
      protected void dispatchEvent(AWTEvent e)
          int id = e.getID();
          if(wait_ && (id == MouseEvent.MOUSE_PRESSED) ||
                      (id == MouseEvent.MOUSE_RELEASED) ||
                      (id == KeyEvent.KEY_PRESSED) ||
                      (id == KeyEvent.KEY_RELEASED)) // or check if its an InputEvent class
            // do nothing
          else
            super.dispatchEvent(e);
    }and in your code somewhere you would have
      setHourGlass(true);
      EventProcessor.setWait(true);I use this technique for doing my own dialog modality - I got fed up with not being able to move the parent window in Windoze systems when a modal dialog is showing...

  • How ot disable right muse click in Portal

    Hi,
    I want to disable right mouse click button on a Portal screen, when user start using Portal he/she should not be allowed to use right mouse click button like if they click right mouse button it should give a message not allowed.
    How i can do this.Please let me know.
    Regards,
    Pradeep

    One of the terminals on the left side of the event structure returns which button you clicked and you can wire that into a case structure terminal to decide when to execute your code.
    Also, go to File>>VI Properties>>Window Appearance>>Customize and disable the context menus.
    Try to take over the world!

  • Disable Right Mouse Button Popup Menu

    How can I disable right mouse button popup menu for a LabVIEW control to use
    my custom popup menu?
    Alessio Colzi

    Sorry for the stupid question but I forgot that option.
    Thank you Gorka
    Alessio
    "Gorka Larrea" ha scritto nel messaggio
    news:[email protected]..
    > Not sure if can be made under LV 6 but under LV 5.0 you can disable
    > runtime popup menu for all the vi under VI setup right clicking the
    > icon in the right part of the front panel.
    >
    > Another option is to put a transparent decoration over your control,
    > to avoid right clicking.
    >
    > Hope this helps

  • Change/disable mouse-over selection on app switcher menu (apple-tab menu)

    Does anyone know of a way to disable the mouse-over selecting an application on the apple-tab menu (app switcher)? This is so frustrating when you are trying to do a lot of copy and paste between apps and the mouse keeps "re-selecting" the application you are trying to choose.

    Hello,
    Thank you so much for replying so quickly and moreover, solving my problem. I must apologise for not doing more research about this issue by searching these forums more thoroughly. I found a similar post here:-
    http://forums.adobe.com/message/139937#139937
    Your solution goes one step further and eliminates the need to search through the Javascript for the relevant code.
    Thank you again, you've helped me a great deal.
    Best wishes,
    foreverdusty.

  • Mouse right click button, popup menu, PC frozen

    Hello all,
    It has been while I've been noticing this problem.
    Almost every time I click with the right mouse button on an email from the list of emails or a word inside the content of an email to see which words are suggested by the spell checker, the usual popup menu appear but immediately after
    my PC gets frozen. I need to restart it.
    I don't think TB causes that crash, but something indirectly related.
    How can I debug this? (I'm software developer)
    Thank you so much.
    Roberto

    Update1:
    I put my attention only in the main TB menu.
    I disabled the TB extensions (only Lighting and EnigMail) and tried again to play with the main TB menu.
    With this new TB GUI, you don't see directly the main menu. I usually click the ALT key and the main menu will be displayed. After that I play with it a bit. That means, I clicked on on Tools or File or View etc items and just moved the mouse cursor over the popup menu, without clicking on a specific submenu item. After a while, some seconds, the PC gets frozen and I need to restard the PC.
    I started TB in safe mode also (-safe-mode). In this mode the main menu appears always so I don't need to click on the ALT key.
    I repeat the same steps of moving the mouse cursor of popup main menu items. Up to now, all is normal, without crashing or freezing.
    PC: Win7 (full updated), x64, TB last version.
    Any idea how can I debug this problem?
    Thanks

Maybe you are looking for