JMenuItem and JPopupMenu

Is there an esay why round this issue?
I've got a JMenuItem that I would like to add to MULTIPLE menu's.
when I add the JMenuItem to a "new" JPopup it dissappears from the previous one.
eg
JPopupMenu menu1 = new JPopupMenu();
JPopupMenu menu2 = new JPopupMenu();
JMenuItem disappearingItem = new JMenuItem("I'll only appear once");
menu1.add(disappearingItem);
menu2.add(disappearingItem);I know I could "just" create a new JMenuItem that is the same, but this seems like a hassle. Why can't I have the same JMenuItem appearing in different menus?
Thanks,
Steve

Hello,
I think its to avoid incosistency.
This is the responsible source-code from java.awt.Container:
/* Reparent the component and tidy up the tree's state. */
         if (comp.parent != null) {
          comp.parent.remove(comp);
                    if (index > ncomponents) {
                        throw new IllegalArgumentException("illegal component position");
            }Ragards,
Tim

Similar Messages

  • Problem with InputVerifier and JPopupMenu

    Hello, I have a problem related to the usage of InputVerifier and JPopupMenu.
    Consider the following scenario:
    - A frame composed of two components: a JTextField and a JComboBox
    - An InputVerifier that was set in the JComboBox (and in its associated JTextComponent)
    - A JPopupMenu which is enabled by a right mouse click over the components of the frame.
    The verify() method of the InputVerifier class is executed every time the focus is on the JComboBox and is requested by other component.
    Suppose that the focus is on the JComboBox, and a right mouse click is executed over this components. In summary, we have:
    1) The method verify() of the InputVerifier associated to the JComboBox is executed
    2) The focus changes from the JTextComponent (associated to the JComboBox) to the JRootPane (associated to the JTextComponent (that is associated to the JPopupMenu)).
    Now suppose that, the user clicks in the JTextField component (note that the JPopupMenu is visible and has the focus). What happens is that the focus goes from the JRootPane -> JTextComponent (associated to the JComboBox) -> JTextField.
    Despite the focus flow through the JTextComponent, the Swing plattaform, when executing the runInputVerifier() in the JComponent context, get the JRootPane component as the focusOwner instead of the JTextComponent.
    In this way, the Swing platform tries to invoke the InputVerify of the JRootPane (that is set with "null"), and the JComboBox InputVerifier is not executed as expected.
    It works as if the focus is flowing from the JRootPane directly to the JTextField.
    However, if the user clicks on the JComboBox before clicking in the JTextField, the Swing platform executes the correct InputVerifier, i.e., the one associated to the JComboBox (actually, the one associated to the JTextComponent).
    Any thoughts to solve this problem?
    Thanks

    A plus information, I am using jdk1.5.0_22.

  • JMenuItem and JTextField doesn't look right after upgrading to Java 8

    I just upgraded to JDK 8u25
    I have a legacy Swing application, which makes use of JMenuItem and JTextField
    I realize, after upgrading, there is a bolder grey vertical border at the left side of JMenuItem and JTextField
    JMenuItem
    JTextField
    This only happen, if I were using look n feel com.sun.java.swing.plaf.windows.WindowsLookAndFeel
    Before that, I never have such problem. Anyone know is there any workaround for such problem?
    Here's the code example to demonstrate the problem.
    package javaapplication5;
    * @author yccheok
    public class NewJFrame extends javax.swing.JFrame {
         * Creates new form NewJFrame
        public NewJFrame() {
            initComponents();
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            jTextField1 = new javax.swing.JTextField();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jMenu2 = new javax.swing.JMenu();
            jMenuItem1 = new javax.swing.JMenuItem();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jMenu1.setText("File");
            jMenuBar1.add(jMenu1);
            jMenu2.setText("Edit");
            jMenuItem1.setText("jMenuItem1");
            jMenu2.add(jMenuItem1);
            jMenuBar1.add(jMenu2);
            setJMenuBar(jMenuBar1);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(21, 21, 21)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(232, Short.MAX_VALUE))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(19, 19, 19)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(230, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
         * @param args the command line arguments
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Windows".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            //</editor-fold>
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                  
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            //</editor-fold>
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                  

    The site looks OK -- actually quite impressive for what appears to be a from-scratch design.
    In Opera 10 under Snow Leopard 10.6.1, the design doesn't start to explode until the horizontally scrolling marquee comes across. I would strongly recommend just removing that marquee; it is an extremely outdated element of web design. If you do that, the design shouldn't blow up on you in other browsers.

  • Accessibilty and JPopupMenu

    I am using JAWS 6 with JDK 1.4.2_06 and Access Bridge 1.2.
    If I add Menuitems to a JMenu which is added to the menubar everything works as expected. One of the menu items is another JMenu, a sub-menu. When JAWS reads this it speaks "submenu" indicating that there is a sub-menu to the right of the current menu item. However, If I attached the exact same menuitems to a JPopupMenu,
    JAWS never speaks "submenu" so the user has no iindication that there is a sub-menu to the right.
    I've taken the attached code from "The JFC Swing Tutorial - Second Edition" and tweaked it slightly so the menubar and popup menu contain the same items.
    It seems as if the accessibility api is expecting the first set of menu items to be attached to a menu parent.
    If worked around this for now by adding another top level menu to the popupmenu to which I add the menuitems.
    Is this a Java or JAWS bug ?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    * Like MenuDemo, but with popup menus added.
    public class TextFieldDemo {
    JTextArea output;
    JScrollPane scrollPane;
    String newline = "\n";
    public JMenuBar createMenuBar() {
    JMenuBar menuBar;
    JMenu menu;
    //Create the menu bar.
    menuBar = new JMenuBar();
    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription(
    "The only menu in this program that has menu items");
    JMenuItem[] mi = createAMenu();
    for(int i=0; i < mi.length; ++i)
    menu.add(mi);
    menuBar.add(menu);
    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription(
    "This menu does nothing");
    menuBar.add(menu);
    return menuBar;
    public Container createContentPane() {
    //Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);
    //Create a scrolled text area.
    output = new JTextArea(5, 30);
    output.setEditable(false);
    scrollPane = new JScrollPane(output);
    //Add the text area to the content pane.
    contentPane.add(scrollPane, BorderLayout.CENTER);
    return contentPane;
    public void createPopupMenu() {
    JMenuItem menuItem;
    //Create the popup menu.
    JPopupMenu popup = new JPopupMenu();
    JMenuItem[] mi = createAMenu();
    for(int i=0; i < mi.length; ++i)
    popup.add(mi[i]);
    //Add listener to the text area so the popup menu can come up.
    MouseListener popupListener = new PopupListener(popup);
    output.addMouseListener(popupListener);
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("TextFieldDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create/set menu bar and content pane.
    TextFieldDemo demo = new TextFieldDemo();
    frame.setJMenuBar(demo.createMenuBar());
    frame.setContentPane(demo.createContentPane());
    //Create and set up the popup menu.
    demo.createPopupMenu();
    //Display the window.
    frame.setSize(450, 260);
    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();
    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());
    private JMenuItem[] createAMenu()
    JMenu submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;
    JMenuItem items[] = new JMenuItem[8];
    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item",
    KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription(
    "This doesn't really do anything");
    items[0]=menuItem;
    menuItem = new JMenuItem("Both text and icon");
    menuItem.setMnemonic(KeyEvent.VK_B);
    items[1]=menuItem;
    menuItem = new JMenuItem("icon only");
    menuItem.setMnemonic(KeyEvent.VK_D);
    items[2]=menuItem;
    //a group of radio button menu items
    ButtonGroup group = new ButtonGroup();
    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    items[3]=rbMenuItem;
    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    items[4]=rbMenuItem;
    //a group of check box menu items
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    items[5]=cbMenuItem;
    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    items[6]=cbMenuItem;
    //a submenu
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);
    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_2, ActionEvent.ALT_MASK));
    submenu.add(menuItem);
    menuItem = new JMenuItem("Another item");
    submenu.add(menuItem);
    items[7]=submenu;
    return(items);

    Hi;
    I want to add chekboxes to a poupup menu ,how can I do that. I already have a submenu with names of columns ton hide and show them using chekcboxes and i want that same menu as a popup when i click in the tableheader.
    thanx

  • JMenuItem and JPanel issues!

    I have a JMenuBar set up for my program and I want each JMenuItem to show a seperate JPanel when clicked. I've tried container.add(panel1); and panel1.setVisible(true); // (Previously set to false) but neither work.
    This is how I've implemented it:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class LibraryGUI extends JFrame {
         private Container container;
         private JPanel addStaffPanel, addStudentPanel;
         private JLabel addStaffTitle, addStudentTitle;
         // Set up GUI
         public LibraryGUI() {
              super("Visual Library 2.0");
              container = getContentPane();
              // Main menu items
              JMenu fileMenu = new JMenu("File");
              JMenu addMenu = new JMenu("Add");
              JMenu removeMenu = new JMenu("Remove");
              JMenu displayMenu = new JMenu("Display");
              // Set up 'File' menu items
              JMenuItem exit = new JMenuItem("Exit");
              // Set up 'Add' menu items
              JMenuItem addStaff = new JMenuItem("Add Staff Member");
              JMenuItem addStudent = new JMenuItem("Add Student Member");
              // Set up the 'File' menu
              fileMenu.add(exit);
              // Set up the 'Add' menu
              addMenu.add(addStaff);
              addMenu.add(addStudent);
              // Create menu bar and attach it to the window
              JMenuBar bar = new JMenuBar();
              setJMenuBar(bar);
              // Add menu's to the menu bar
              bar.add(fileMenu);
              bar.add(addMenu);
              // File --> Exit (THIS WORKS FINE!)
              exit.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        System.exit(0);
              // Set up 'Add Staff Member' title
              addStaffTitle = new JLabel();
              addStaffTitle.setText("Add Staff Member");
              // Set up 'Add Student Member' title
              addStudentTitle = new JLabel();
              addStudentTitle.setText("Add Student Member");
              // Set up 'Add Staff Member' panel
              addStaffPanel = new JPanel();
              addStaffPanel.setLayout(new GridLayout(1,1));
              addStaffPanel.add(addStaffTitle);
              // Add --> Add Staff Member (THIS DOESN'T WORK)
              addStaff.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        container.add(addStaffPanel);
              // Set up 'Add Student Member' panel
              addStudentPanel = new JPanel();
              addStudentPanel.setLayout(new GridLayout(1,1));
              addStudentPanel.add(addStudentTitle);
              // Window settings
              container.setBackground(Color.WHITE);
              setSize(600, 400);
              setVisible(true);
         public static void main(String args[]) {
              LibraryGUI application = new LibraryGUI();
              application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }It compiles fine, no errors. But when the menu items are clicked it just does nothing. Any ideas?
    - Will

    Hmm, normally after adding/remove component to/from a panel you would need to use panel.revalidate. However, this didn't seem to work. Playing around I came up with the following:
    container.setVisible(false);
    container.removeAll();
    container.add(addStudentPanel);
    container.setVisible(true);
    However, instead of using this approach I suggest you look at using a CardLayout. This Layout Manager was designed for this situation, to replace the entire contents of a panel with multiple different panels. Read this section from the Swing tutorial on Using Layout Managers:
    http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html
    An added bonus when using the CardLayout is that you can share the same ActionListeners for all panels. When adding a panel to the CardLayout you need to give a name to the panel (eg. "staff", "student"). When you create your menu items you can use the setActionCommand(...) method:
    addStaff.setActionCommand("staff");
    addStudend.setActionCommand("student");
    Now in your action listener you would just use the event.getActionCommand() method to determine which card panel to display.

  • JMenuItem and MouseListener

    Hi there!!
    I'm working with nested menus.
    Anyone knows if a JMenuItem doesn't catch mouseClicked() event when it belongs to a nested menu?
    I can work with mousePressed() and mouseReleased() as a "mouse click", but i'd like to know the answer to it.
    Regards, eyitikawa

    S. pschugg, thanks for the reply.
    I was using ActionListeners too.
    But I need a effect of "on mouse over" a JMenuItem change its style and "on mouse out" the same returns to its original state. That's why I changed to MouseListener.
    Does anyone ever needed this kind of effect?
    Regards, eyitkawa.

  • Netbeans and JPopupMenu

    Im having a problem creating a JPopupMenu,
    Im using the netbeans GUI builder, I've added the popup menu to the Jframe, and can get it to display itself when right clicked, however i cannot get it to hold any components.
    I tried adding a menu item to it, first by dragging and dropping, which did not work, then by right clicking and adding from pallete, which did work.
    However, the menu item is not diplayed.
    I tried adding various other containers too, but they are not displayed either, any ideas what im doing wrong?
    Thanks,
    James

    Yes quite, netbeans is absolutley fine, frankly, the java website suggests using it for gridbag... Some people just like to feel 1337.
    Curiously its working now, kinda.
    There seems to be a bug of somesort that causes the palette to empty, at which point i have to recreate the project and it comes back, since then however, the popupmenu seems to work, although the offset is a bit wonky
    jPopupMenu1.setLocation(evt.getX(), evt.getY());
                jPopupMenu1.setEnabled(true);
                jPopupMenu1.setVisible(true); that should put the menu where the mouse was at the time, however it seems to be off slightly, any ideas why?

  • JMenu,JMenuItems and JRadioButtonMenuItem

    Hi I have a JMenu in the JMenuBar.I have a JMenu in it and Then I have 6 JMenuItems which are Of the JRadioButtonMenuItems.
    I need to get on of it selected manually .Can somebody help me in this.I am able to get the name if the MenuItems but I am not able to get it selected.
    Thanks in advance.

    Read this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]Using Menus for an example.

  • JCheckBox and JPopupMenu

    I have a JPopupMenu containing several checkboxes within some submenus. Everytime I select one check box, the popup menu closes and I have to do it all over again. Is there any way to allow multiple selections in a JPopupMenu?
    Thanks!

    I have it set up so when I select a specific checkbox a popup menu appears right next to it. A dialog would be nice, but I have put too much time into this to change it now. Any thoughts about how to keep the popup menu open while selections are being made? Thanks for replying so quick!

  • Problem with  JTree and JPopupMenu

    Hi,
    I'm using a JPopupMenu with a JPanel in it. In the panel
    I want to have a JTree. I can build the tree without
    problems but when I try to "go down" in the tree it
    vanishes. This happens only the first time that I
    access a node. When I initialize the menu a second
    time the node I just pressed works fine.
    What is the problem????
    Here is a sample of my code.
    popUpMenu = new JPopupMenu();
    thePanel = new JPanel();
    thePanel .setLayout(new GridBagLayout());
    popUpMenu .add(thePanel );
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The top");
    DefaultMutableTreeNode secondNode = null;
    DefaultMutableTreeNode firstNode = null;
    firstNode = new DefaultMutableTreeNode("One node");
    top.add(firstNode);
    secondNode= new DefaultMutableTreeNode("One node");
    firstNode.add(secondNode);
    buildConstraints(gbc, 1, 0, 1, 5, 5, 5, 5, 2, 1); //My contraintsmethod
    JTree tree = new JTree(top);
    thePanel .add(tree, gbc);

    Mate, why are you putting a JPanel in a JPopupMenu? I'd be interested to look at a screenshot of this.
    Mitch

  • JMenuItem and MouseListener Problems

    I add the MouseListener to the JMenu, the event works.
    but when I add the MouseListener to the JMenuItem, it didn't work?
    why?
    the following is my code:                         jMenuItemRelogin = new JMenuItem();
                             jMenuLogin.add(jMenuItemRelogin);
                             jMenuItemRelogin.setText("Relogin");
                             jMenuItemRelogin.addMouseListener(new MouseAdapter(){
                                  public void mouseClicked(MouseEvent evt){
                                       reloginMouseClicked(evt);
                             });

    You don't use MouseListeners. You use ActionListeners.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]How to Use Menus for working examples.

  • JTable And JPopupMenu

    Hello, In a JTable i want when the user press the right button of the mouse to chose an action on JPopupMenu it automaticly select the row where the Press The Right Button.

    In your MouseListener you use table.getRowAtPoint(...) to get the row, then you can use table.setRowSelectionInverval(...) to select the row.

  • How can I distinguish a JMenuItem , JPopupMenu and TopLevelMenu?

    I used the following methods to get the component who (a menu)gains the focus:
    JComponent com = JFrmame.getFocusOwner();
    or
    MenuSelectionManager menuMgr = MenuSelectionManager.defaultManager();
    MenuElement[] menuPath = menuMgr.getSelectedPath();
    if(menuPath != 0) {
    JComponent comp = Array.get(menuPath, menuPath.length-1); // this is the item with the focus
    then I need to use getAction() to get the menuItem's action. But how can I filter JMenuItem and JPopUpMenu from TopLevelMenu (JMenuBar item) ?
    Thanks!

    The instanceof may provide the simplest solution, since JPopupMenu, JMenuBar and JMenuItem don't have any kind of ancestor relationship with each other.if (comp instanceof JPopupMenu) {
        // Popup
    } else if (comp instanceof JMenuItem) {
        // Item
    } else if (comp instanceof JMenuBar) {
        // Bar
    } else ...?Hope this helps,
    -Troy

  • Showing multiple popups

    Hey all,
    I am trying to implement my own menu system by subclassing JMenu, JMenuItem, and JPopupMenu. Everything works fine, except for one glitch: when what should be a submenu opens, the main menu closes because they are both popups and swing only allows one popup to display at a time. Looking through the source I can't see how JMenu gets around this. Can anyone offer a suggestion?
    I see JPopupMenu.isSubPopupMenu(), but that is package private and, as far as I can tell completely unused. I also see PopupMenu.setInvoker() but that does not have the desired effect.
    Thanks!
    bjorn

    user12952952 wrote:
    Hey all,
    I am trying to implement my own menu system by subclassing JMenu, JMenuItem, and JPopupMenu.Why? That is, what behavior are you changing that merits subclassing?
    There may be a solution for your requirements that doesn't involve subclassing.
    db

  • Jpopupmenu, jmenuitem, jmenu... transparent

    I have extended JPopupmenu, JMenuItem, and JMenu in order to obtain some behaivier (transparent menus). Im having this prob. that the JMenu creates a normal JPopupMenu, where I would like it to use my extended JPopupMenu. I thought about overriding the method in JMenu which creates the JPopupMenu, but the JPop is private in jmenu. How to do this? I could ofcourse copy all the code of the jmenu class and just change the creation of the jpopupmenu, but that is probably illegal or something. Any ideas?
    Stig.

    I have the same problem.
    I run my code in jdk1.3 and it works great. But in 1.4, the transparency is gone, and depeneding on the implementation, the repainting sometimes gets real crazy.

Maybe you are looking for