Results 1 to 2 of 2
  1. #1
    shahid0627 is offline Member
    Join Date
    Aug 2009
    Posts
    16
    Rep Power
    0

    Default How can I add popUp menu on a tab of a tabbedPane?

    I want to add a popUp menu on a tab of a TabbedPane when I click on the tab.That is,suppose,there are two tabs A and B.When I clicked on A,there will appear a popup menu on A and when I clicked on B there will be another popUp menu on B.How can I do this?plz give me suggestions.The popUp menus will appear only on respected tabs.
    Thanks,
    Shahid0627
    Last edited by shahid0627; 08-27-2009 at 07:04 PM.

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    JTabbedPane has a method for this: setTabComponentAt().
    Call this method to set the contents of the tab itself to a Component.
    That component can have a popup menu.

    To handle mouse clicks on the tab, in my program I override fireStateChanged in the JTabbedPane:
    Java Code:
        protected void fireStateChanged() {
            int newState = getSelectedIndex();
            boolean noswitch = true;
    
            if (newState == backButInx)
                { use tab as a button: perform an action }
            else if (newState == rotButInx)
                { use tab as a button: perform an action }
            else noswitch = false;
            if (noswitch)
                setSelectedIndex(diagramPanelState);  // back to previous state
            else {
                super.fireStateChanged();
                diagramPanelState = getSelectedIndex();
            }
        }
    In your case you would replace "use tab as a button: perform an action" with popping up the popup menu.

Similar Threads

  1. Regarding popup menu in netbeans IDE
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 03-11-2009, 02:14 PM
  2. Adding popup Menu on animation
    By Peggy in forum Java Applets
    Replies: 2
    Last Post: 12-10-2008, 09:33 AM
  3. add PopUp menu by NetBeans
    By hungleon88 in forum AWT / Swing
    Replies: 1
    Last Post: 09-12-2008, 02:05 PM
  4. Replies: 0
    Last Post: 07-25-2008, 03:32 PM
  5. Replies: 7
    Last Post: 05-09-2008, 08:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •