Popup Menu on JPanel

Howdy,
I have a JPanel with various controls on it, like JButton JLabel etc. I'd like to have a popup menu appear from the JPanel regardless of whether the user rightclicks over a JButton or over the JPanel itself. One way this can be done is to trap the rightclick on each control and then pass it on to the JPanel. Is there a simpler solution to this?
Thanks

you might be able to override the processMouseEvent method on the JPanel and handle it there. I think that method delegates to the components inward. Not sure.

Similar Messages

  • JPopupMenu with JInternalFrame, popup menu doesn't work

    hi, i have this problem, as shown in the sample code at the end of this post.. basically, i have a table, and i added a JPopupMenu onto the table.. the popup menu works well when running the table class, though, when i call the table class in a JInternalFrame environment, the popup menu won't work.. anyone know why?
    ///Basic sample table code, when run this alone, the popup menu will work
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TableBasic extends JPanel
         private JTable table;
         public TableBasic()
              String[] columnNames = { "Date", "String", "Integer", "Boolean" };
              Object[][] data =
                   {  { new Date(), "A", new Integer(1), Boolean.TRUE },
                        { new Date(), "B", new Integer(2), Boolean.FALSE },
                        { new Date(), "C", new Integer(9), Boolean.TRUE },
                        { new Date(), "D", new Integer(4), Boolean.FALSE}
              table = new JTable(data, columnNames)
                   //Returning the Class of each column will allow different
                   //renderers to be used based on Class
                   public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              JScrollPane scrollPane = new JScrollPane(table);
              add(scrollPane);
         public void createPopupMenu()
              JMenuItem menuItem;
              //Create the popup menu.
              JPopupMenu popup = new JPopupMenu();
              menuItem = new JMenuItem("A popup menu item");
              //menuItem.addActionListener(this);
              popup.add(menuItem);
              menuItem = new JMenuItem("Another popup menu item");
              //menuItem.addActionListener(this);
              popup.add(menuItem);
              //Add listener to the text area so the popup menu can come up.
              MouseListener popupListener = new PopupListener(popup);
              table.addMouseListener(popupListener);
         public static void main(String[] args)
              JFrame frame = new JFrame();
              TableBasic table = new TableBasic();
              table.createPopupMenu();
              frame.setContentPane(table);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              //frame.setLocationRelativeTo(null);
              frame.setVisible(true);
         class PopupListener extends MouseAdapter
              JPopupMenu popup;
              PopupListener(JPopupMenu popupMenu)
                   popup = popupMenu;
              public void mousePressed(MouseEvent e)
                   maybeShowPopup(e);
              public void mouseReleased(MouseEvent e)
                   maybeShowPopup(e);
              private void maybeShowPopup(MouseEvent e)
                   if (e.isPopupTrigger())
                        popup.show(e.getComponent(), e.getX(), e.getY());
    ///when integrate the previous table into here, popup menu won't work
    import java.awt.*;
    import javax.swing.*;
    public class InternalFrameBasic
         extends JFrame
         //implements ActionListener
         private JDesktopPane desktop;
         private JInternalFrame menuWindow;
         public static final int desktopWidth = 800;
         public static final int desktopHeight = 700;
         public InternalFrameBasic(String title)
              super(title);
              //Set up the GUI.
              desktop = new JDesktopPane();
              desktop.putClientProperty("JDesktopPane.dragMode", "outline");
              //Because we use pack, it's not enough to call setSize.
              //We must set the desktop's preferred size.
              desktop.setPreferredSize(new Dimension(desktopWidth, desktopHeight));
              setContentPane(desktop);
              createMenuWindow();
              desktop.add(menuWindow); //DON'T FORGET THIS!!!
              Dimension displaySize = menuWindow.getSize();
              menuWindow.setSize(desktopWidth, displaySize.height);
         private void createMenuWindow()
              menuWindow =
                             new JInternalFrame("Event Watcher", true, //resizable
                                                                                                   true, //closable
                                                                                                   false, //not maximizable
                                                                                                   true); //iconifiable
              menuWindow.setContentPane(new TableBasic());
              menuWindow.pack();
              menuWindow.setVisible(true);
          * Create the GUI and show it.  For thread safety,
          * this method should be invoked from the
          * event-dispatching thread.
         private static void createAndShowGUI()
              //Make sure we have nice window decorations.
              //JFrame.setDefaultLookAndFeelDecorated(true);
              //Create and set up the window.
              JFrame frame = new InternalFrameBasic("Example Internal Frame");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args)
              //Schedule a job for the event-dispatching thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        createAndShowGUI();
    }

    table.createPopupMenu();The above line should not be in the main method. It should be in the constructor class of TableBasic.
    You never execute that method in your InternalFrameBasic class to the mouse listener never gets added to the table.

  • Popup menu does not show in JTextField

    I have a JPanel with a popup menu that works perfectly, as long as the right mouse button is clicked on the JPanel. However the popup menu does not show if the right mouse button is clicked on a JTextField that is within the JPanel.
    What has to be done that the popup menu shows always?
    this.addMouseListener(new java.awt.event.MouseAdapter()
    public void mouseReleased(MouseEvent e)
    this_mouseReleased(e);
    protected void this_mouseReleased(MouseEvent e)
    if (e.isPopupTrigger())
    popPopup.show(this, e.getX(), e.getY());

    There are up to 20 JTextFields in the JPanels an the application has a lot of JPanels of course. Adding the listener to each and every JTextField means a lot of extra code. Is there really no generic solution to this problem???

  • 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.

  • How to get system popup menu in java?

    I want to know how to get windows xp or any operating systems default popupmenu in java.
    And i also have problem for using mnemonic for JPopupMenu, it works well when i first press right click of my mouse and use the specified mnemonic for that the action specifed for that is triggered but when is use mnemonic without the using my mouse it doesn't trigger why.

    Please how to get native(e.g windows explorer) popup menu in jfilechooser

  • Creating Popup Menu in Desktop Intelligence

    I need help creating a popup menu in the Tool menu of Deski.
    This popup needs to be visible when a report is open or when no report is open.
    It's my first add-in and I can't make my code work.
    Sub BuildMyMenu()
    Dim PopMenu As CmdBarControl
    Dim CleanPop As CmdBarControl
    Dim unvButton As CmdBarControl
    Dim lsiButton As CmdBarControl
    On Error Resume Next    'disable errors temporarily
    Set PopMenu = Application.CmdBars(1).Controls("&Tools").Controls("&Clean-Up Utility")
        If Err.Number = 0 Then  'button already exists
            Button.Delete       'delete it so that it can be re-defined
        Else
            Err.Clear           'clear the error so other testing can take place
        End If
    Set PopMenu = Application.CmdBars(1).Controls("&Tools").Controls.Add(boBarPopup)
    PopMenu.Caption = "&Clean-Up Utility"
    PopMenu.DescriptionText = "Clean-Up Utility"
    PopMenu.TooltipText = "Clean-Up Utility"
    Set unvButton = PopMenu.CmdBarPopup.Controls.Add(boControlButton)
    unvButton.Caption = "C&lean-Up Universe..."
    unvButton.DescriptionText = "Clean-Up Universe"
    unvButton.TooltipText = "Clean-Up Universe"
    unvButton.OnAction = filename(ThisDocument) & "!ShowUserForm2"
    Set PopMenu = Application.CmdBars(2).Controls("&Tools").Controls("&Clean-Up Utility")
        If Err.Number = 0 Then  'button already exists
            Button.Delete       'delete it so that it can be re-defined
        Else
            Err.Clear           'clear the error so other testing can take place
        End If
    Set PopMenu = Application.CmdBars(2).Controls("&Tools").Controls.Add(boBarPopup)
    PopMenu.Caption = "&Clean-Up Utility"
    PopMenu.DescriptionText = "Clean-Up Utility"
    PopMenu.TooltipText = "Clean-Up Utility"
    Set unvButton = PopMenu.CmdBarPopup.Controls.Add(boControlButton)
    unvButton.Caption = "C&lean-Up Universe..."
    unvButton.DescriptionText = "Clean-Up Universe"
    unvButton.TooltipText = "Clean-Up Universe"
    unvButton.OnAction = filename(ThisDocument) & "!ShowUserForm2"
    End Sub
    What I need is a popup menu from the Tools menu, that says "Clean-Up Utilities". From that popup menu, 2 more buttons: one that says "Clean-Up Universes" and the other "Clean-Up LSI".
    Thanks for your help.

    In what way, exactly, isn't it working? Do you see the pop up menu at all?
    Did you make sure that JS is enabled in your Acrobat?
    I've ran the code and it seems to work fine for me. However, I don't quite
    get what it's supposed to do.
    Is it supposed to take the user to a specific page, or to a named
    destination? It seems like it's trying to do both, which doesn't make much
    sense.

  • Copy data from one sheet to another based on content of popup menu

    I'm trying to create a spreadsheet to help teachers grade students during reading time in my school.  If you're interested in the specifics of it, the long version is in the following paragraph:
    I work in a high school, and 10% of each student's English class grade is supposed to come from reading during what is called "Enrichment time," a 20-minute daily reading time.  This occurs at the beginning of the second period of the school day.  With a few rare exceptions, students are not in their English teacher's class for this reading time; their 2nd period teacher, whether a teacher of math, science, English, or history, or whatever, records a daily grade for each student, based on whether or not the student is reading during enrichment time. In the past, teachers have recorded the grade of each student on a separate sheet of paper, then gone to the teachers' lounge and sorted through their students' grade sheets, putting each student's sheet into a folder for the student's English teacher to grade. Next year every teacher will have an iPad, so I'm trying to create a cloud-shared numbers spreadsheet that could help solve the problem of teachers not communicating well.  I've settled upon the solution of giving each teacher with a 2nd period Enrichment group access to a spreadsheet that would be accessible to all the English teachers as well.  The enrichment teacher would enter the students' names on teh far left hand side, then with each student's name the teacher's name would be indicated in a popup menu.  The first sheet is where the 2nd period enrichment teacher would enter the data, and then the different English teachers would, ideally, have a separate sheet with only their students populating that sheet. 
    tl;dr:
    I need sheet 2 to be populated with whole rows of data from sheet 1, and I want sheet 2 to only include rows which have a specific choice selected in a popup menu.
    Here's the document, via iCloud:
    https://www.icloud.com/iw/#numbers/BAL2c7eirUmlW1C8CvqB7F6X9LlhwHB3bHWF/Enrichme nt_Template

    A,
    It seems that your iCloud Numbers document is protected by password.
    Jerry

  • Opening pdf in ADF popup menu

    Hi All,
    I have big issue in opening a pdf file under ADF popup menu. currently, the popup menu is working fine and but i dun know how to load the pdf once the popup menu is loaded. I tried to put javascript code in <body> with "onLoad=...", however, i dun know how to load pdf from javascript.
    Any one has a good idea to get around this problem???
    Cheers,
    -T

    Hi!
    I would like to insert a pdf file into the database and then display it. Actually I do not know how to insert the file into the db nor how to extract it. I use a library (jpedal) to show the pdf and am able to represent a byte stream, but how do I get it?
    regards,
    Mario Udina

  • In iCloud Numbers how do I set up a popup menu in an entire column

    I have a database using iCloud Numbers. The table is for my tax deductions for 2014. In one column I have Doctors/Dentists/etc. Instead of typing that title each time I create a new entry in that column, how can I set a popup menu like I can in Excel and choose Doctors/Dentists/etc?

    Hi Aunest,
    You have couple of options here.
    You can make a copy of the site-wide template for every catalogue and build the menu manually.
    The other option is to use:
    {module_cataloguelistdump,-1,rowLength,targetFrame,sortBy}
    Displays the List of all Catalogues as names that are links to those catalogues
    Parameters:
    Use -1 to display parent catalogs, use -2 to display all catalogs including sub-catalogs or a catalogue ID to display the subcatalogues of a particular catalogue
    rowLength - will limit the number of items per row when items are displayed as a list. Default is 1 item per row.
    targetFrame - e.g. _blank. Specify the frame you want the item to open in
    sortBy - will sort the web apps in specified order
    Alphabetical - sorts items alphabetically
    Weight - sorts items by weight
    Example
    {module_cataloguelistdump,-1,1,_blank,Alphabetical} - this module will display the catalogue list in the new window, alphabetically and all in one column
    Cheers,
    -mario

  • How do I add an entry in Project Explorer's popup menu

    Is it possible to add my own entries in the popup menu of Project Explorer?
    I'm considering writing an LabVIEW addin that adds extra functionality to the Project Explorer, but I need a way to extend the context menu.
    /Leif

    LeifS wrote:
    Is it possible to add my own entries in the popup menu of Project Explorer?
    I'm considering writing an LabVIEW addin that adds extra functionality to the Project Explorer, but I need a way to extend the context menu.
    /Leif
    It is probably possible with digging deep into the contents of your "LabVIEW/resources" folder but will have a number of drawbacks. First your VI will need to provide a specific (undocumented) and most probably not so trivial interface that will be hard to uncover. It will somehow need to tell the project Explorer what it's name is and for what types of files or containers it should be displayed.
    Then those hooks will likely change between each LabVIEW version too as the Project Explorer is still a project under development. So unless there is an unlikely document here on ni.com that describes this (and which a search should clearly give you if there) I think it is simply not worth the hassle to dig into this.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Where is the Popup Menu in ACR 9?

    After installing ACR 9, I don't see the Popup Menu on top of the Firmstrip. All I see are the "Select All" and "Synchronize...". Right clicking on the firmstrip is not doing anything.
    Thank you.

    3js@adobe wrote:
    Nothing like you said on the menu bar.
    Right you are using CS6. Sorry.

  • Popup menu values

    Lets say I have a button that opens a popup menu with 2 levels:
    Fruits> Apple
                Banana
                Melon
    Vegetables> Carrot
                         Potato
                         Tomato
    Is it possible to get both values? I mean, to receive information if fruits or vegetables was selected and also what kind of fruit/vegetable.
    Thanks in advance.

    Hi,
    You could use the cReturn property to encode a value that lets you determine both values, such as;
    var choice = app.popUpMenuEx(
         {cName: "Fruits",
          oSubMenu: [ {cName: "Apple", cReturn: "Fruit,Apple" }, {cName: "Banana", cReturn: "Fruit,Banana" }, {cName: "Melon", cReturn: "Fruit,Melon" } ]},
         {cName: "Vegetables",
          oSubMenu: [ {cName: "Carrot", cReturn: "Vegetables,Carrot"}, {cName: "Potato", cReturn: "Vegetables,Potato"}, {cName: "Tomato", cReturn: "Vegetables,Tomato"} ]});
    if (choice !== null)
        var selection = choice.split(","); 
        app.alert("You selected the \"" + selection[1] + "\" menu item from the \"" + selection[0] + "\"");
    Not ideal as you are effectively coding up the menu structure twice (and assumes you will never use a comma character in a menu item name).
    Regards
    Bruce

  • "Java Applet Window" appears in my popup menu

    Hello
    I have added a popup menu to my applet but whenever the popup menu appears, I also get the text "Java Applet Window" at its bottom.
    What is causing this?
    Can I get rid of it?

    Yes you can add a local user policy or local system policy that grants an AWT permission that regards "Java Applet Window" more precisely permission java.awt.AWTPermission "showWindowWithoutWarningBanner";
    You can use a tool to add policy, create new policy files etc. Read about "policytool" in http://java.sun.com/j2se/1.4.1/docs/tooldocs/tools.html
    Probably, signing tha applet jar, you can obtain necessary permission without modifing local policy. But I'm not sure.
    Stefano.

  • Popup containing a JPanel with a JComboBox

    I like to get a Popup containing a JPanel with a JComboBox and some other stuff.
    There are two difficulties:
    - it is not possible to use a Combobox with a light weight popup. So I set combobox.LightWeightPopupEnabled(false). Otherwise the combobox popup won't be shown.
    - If the user changes the popups size (see code: this.getSize() returns a different dimension because of a new Frame size). The combobox popups won't be shown proper after a while.
    Does someone know, why it is not possible to use comboboxes with light weight popups?
    Does somebody know, how to fix the size problem?
    I am using JDK 1.4.1 for Windows Systems.
      private Popup getPopup(){
        if (popup != null) {
          hidePopup();
        Point p = this.getLocationOnScreen();
        Dimension inputSize = this.getSize();
        Dimension tableSize = tablePopup.getSize();
        if( ( p.y + tableSize.height ) < screenSize.height) {
          // will fit below input panel
          popup = factory.getPopup( this, tablePopup,
                                    p.x, p.y + (int)inputSize.height );
        } else {
          // need to fit it above input panel
          popup = factory.getPopup( this, tablePopup,
                                    p.x, p.y - (int)tableSize.height );
        return popup;

    Ok, it works proper with Windows L&F. So I replaced
    private PopupFactory factory =  PopupFactory.getSharedInstance();by
    private WindowsPopupFactory factory = new WindowsPopupFactory();

  • FW 8 popup-menu in CSS problem with IE7 & Safari

    Hi,
    hope that anyone out there got some ideas in my issue. I was
    already searching the forum for advice, but couldn't find
    meaningful infos.
    Here is my problem:
    I designed a page in FW8 (Mac) with a nice popup-menu. I
    exported this thing into DW8 having set the option to export the
    menu as CSS and slices to layers. Then I rearranged the html File
    and included some editable regions, as it was to be used as an
    template.
    Everything works fine in Firefox but IE7 and Safari
    experience some problems.
    The popup-layers are displayed behind the main text-area and
    not in front of it - this makes navigation a bit complicated.
    So teh menu is displayed with text and everything, but behind
    the main text.
    What I tried:
    I tried to reset the z-Index of the popup-layers to values
    below 10 (were set to 500) - didn't help.
    I gave every single item a z-index - didn't help.
    I gave the main text area an z-index of 0 or -1 - made the
    layer disappear.
    I reexported the whole thing - made me just crazy.
    I worked through the css file for errors - maybe I'm not to
    good in CSS ;)
    I checked the forums, but could only find issues where the
    menu was not displayed at all or the text was missing - doesn't
    apply.
    -- no more ideas :(
    Link to my page:
    Website
    Link
    I really appreciate your help! Any comments welcome!
    patrick

    > I think it's a bug with ie7. It doesn't support
    javascript completely,
    > nor
    > does it css.
    I don't think this is accurate. Each browser supports things
    differently,
    and CSS is no exception, but support for javascript is fairly
    reliable
    across the board.
    > but I can't find one that I can use my own images, yet
    Then you are not looking in the right place. Go here -
    http://www.projectseven.com/
    and examine their extensive collection of menu products.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "udigrudi" <[email protected]> wrote in
    message
    news:ful3t7$n9u$[email protected]..
    > I've had a similar problem, menus made in Fireworks 8
    don't show up
    > completely
    > in ie7 for windows either. The menu shows up, but the
    text of submenus
    > with
    > submenus doesn't show up.
    >
    > I think it's a bug with ie7. It doesn't support
    javascript completely,
    > nor
    > does it css.
    >
    > Since your website has disappeared, I'm sorry I can't be
    of more help.
    > I'm
    > thinking of getting a "third party" submenu generator
    (but I can't find
    > one
    > that I can use my own images, yet)
    >

Maybe you are looking for

  • Naming.lookup() returns null???? Why??

    I read about this in a previous forum but there was no answer given to someones question about it. Sometimes Naming.lookup() returns null and a later call will succeed. Is there a recognised reason for this? Is it a recognised bug or undocumented fea

  • Non-functionality in ValueList in CFReport

    I've seen postings looking for a resolution, but never a resolution. Is there a way to get ValueList to work within a calculated field in a CFR? I constantly get an error stating that the field does not exist, even though I clicked my way through the

  • Dasylab runtime: unknown module

    Hallo! I need help with my Dasylab. I Use Dasylab on Win 7 and Win XP. The full version works fine. Now we have an Runtime version for our customer. When I try to open the prebuild worksheet I get an errormessage that there are unknown moules in the

  • TS3747 can I download internet explorer to Macbook Pro to view pic gallery on a website

    Why can't I view a pic gallery & youtube video in Safari browser? I got message stating there's a missing plugin.

  • Can I record my scrolling thru a paused video and make it a video?

    Using ISight I record a clip. When I use the mouse and scroll thru the clip while it is paused I get some great effects. Can I record what I am doing and make it into video footage? Any help in this matter would be greatly appreciated.