Results 1 to 6 of 6

Thread: Confused with JPopupMenu class

  1. #1
    Join Date
    Dec 2009
    Posts
    67

    Confused with JPopupMenu class

    Hello Friend,

    I need you help to get solution over one of may java query. Currently I am studying the class concept of java programming. In which the 'JPopupMenu class' is complex class of java. I am not able to get functionality of 'JPopupMenu class' of java. I also don't have any idea about it's constructors. If you have sound knowledge about the JPopupMenu class of java, then please let me know the same. Your help would be greatly appreciated.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Confused with JPopupMenu class

    Hi,

    A JPopupMenu class is used for an implementation of a popup menu - a small window that pops up and displays a series of choices. A JPopupMenu is used for the menu that appears when the user selects an item on the menu bar. It is also used for "pull-right" menu that appears when the selects a menu item that activates it. Finally, a JPopupMenu can also be used anywhere else you want a menu to appear. For example, when the user right-clicks in a specified area.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Confused with JPopupMenu class

    Example of JPopupMenu class of java:
    Code:
    import javax.swing.JPopupMenu;
    import javax.swing.JTextField;
    import javax.swing.KeyStroke;
    
    public class JPopupMenuDM {
    
      public static void main(final String args[]) {
        JFrame frame = new JFrame("Popup Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        final JTextField textField01 = new JTextField();
        frame.add(textField01, BorderLayout.NORTH);
    
        final JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem01 = new JMenuItem("Option 1");
        popup.add(menuItem01);
    
        JMenuItem menuItem02 = new JMenuItem("Option 2");
        popup.add(menuItem02);
    
        
        ActionListener actionListener = new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            popup.show(textField01, 10,10);
          }  };
        
        KeyStroke keystroke1 =
          KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, 0, false);
        textField01.registerKeyboardAction(actionListener, keystroke1,
          JComponent.WHEN_FOCUSED);
    
        frame1.setSize(350, 150);
        frame2.setVisible(true);
      }
    
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Confused with JPopupMenu class

    Hi friend,

    Please refer following some important methods of the JPopupMenu class:
    • insert(Component compt, int indx)
    • getComponentIndex(Component compt)
    • createActionComponent(Action actnc)
    • createActionChangeListener(JMenuItem mnt)
    • addPopupMenuListener(PopupMenuListener lstn)
    • add(JMenuItem mtn)

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Confused with JPopupMenu class

    In following example of JPopupMenu class, I have used the 'getPopupMenu()' method of the JPopupMenu class. Please review it carefully:
    Code:
    import javax.swing.JMenu;
    javax.swing.JPopupMenu
    import javax.swing.JMenuItem;
    
    public class JPopupMenuMain 
    
    {
      public static void main(String[] argvb) throws Exception 
    
    {
        JMenu menuX = new JMenu("Menu Label");
        menuX.add(new JMenuItem("Item Label"));
    
        boolean lwPopupX = menu.getPopupMenu().isLightWeightPopupEnabled(); // true
    
        menuX.getPopupMenu().setLightWeightPopupEnabled(false);
      
       }
    }

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Confused with JPopupMenu class

    Hi,

    There are six nested class contained in the JPopupMenu class which are mentioned below:
    1. Container.AccessibleAWTContainer
    2. Component.AccessibleAWTComponent
    3. JPopupMenu.Separator
    4. JComponent.AccessibleJComponent
    5. Component.FlipBufferStrategy
    6. JPopupMenu.AccessibleJPopupMenu

Similar Threads

  1. Confused about Scrollbar class
    By Jagruti23 in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 04:18 PM
  2. Confused about the List class
    By Jagruti23 in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 04:17 PM
  3. Confused with JSpinner class
    By Bottlenecked in forum Software Development
    Replies: 4
    Last Post: 15-02-2010, 09:51 AM
  4. Confused with OverlayLayout class
    By Bottlenecked in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 09:37 AM
  5. Confused with 'Class SpinnerNumberModel'
    By Khan Baba in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 11:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,703,649.00093 seconds with 16 queries