PopupMenu in JMenuItem

Hi. I have a JMenu which has several JMenuItems added to it. When an item is right-clicked, I would like a JPopupMenu to be displayed. This can be done by creating a custom MenuUI and only firiing actions on left clicks and showing the popup menu on right-click.
The problem is that when the popup menu appears the underlying menu disappears, which I do not want to happen (I'm trying to achieve the effect of a favorites menu in a web browser where you can right click a favorite item and edit, delete, etc).
Does anyone have a good way to do this?
Thanks,
Jeff

This is the only way I can think of, but it's a nasty hack.
You can add your popup code in the else of the if in mousePressed.
setUI(new BasicMenuUI() {
    MouseInputListener listener;
    protected MouseInputListener createMouseInputListener(JComponent c) {
        listener = super.createMouseInputListener(c);
        return new MouseInputListener() {
            public void mouseClicked(MouseEvent e) {
                listener.mouseClicked(e);
            public void mousePressed(MouseEvent e) {
                if (!(e.getButton() == MouseEvent.BUTTON3))
                    listener.mousePressed(e);
            public void mouseReleased(MouseEvent e) {
                listener.mouseReleased(e);
            public void mouseEntered(MouseEvent e) {
                listener.mouseEntered(e);
            public void mouseExited(MouseEvent e) {
                listener.mouseExited(e);
            public void mouseDragged(MouseEvent e) {
                listener.mouseDragged(e);
            public void mouseMoved(MouseEvent e) {
                listener.mouseMoved(e);
});

Similar Messages

  • Show PopupMenu in JMenuItem

    I want to show the popupmenu when users do the right click on the
    menuitem to do something like the mozilla or internet explorer
    Favorites menu which can be do right click to show the popup.
    I tried this, but i always have the following problems:
    java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.grabContainer(Unknown Source)
    at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.requestAddGrab(Unknown Source)
    at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.stateChanged(Unknown Source)
    at javax.swing.MenuSelectionManager.fireStateChanged(Unknown Source)
    at javax.swing.MenuSelectionManager.setSelectedPath(Unknown Source)
    at javax.swing.JPopupMenu.setVisible(Unknown Source)
    at javax.swing.JPopupMenu.show(Unknown Source)
    at test.jessy.menu.TestSimplePopup$1.mousePressed(TestSimplePopup.java:34)
    This is my test code, I can compile and run it. But the error occurs
    when I do the right mouse click on the "http://java.sun.com" jmenuitem
    of this code. Aims to show the popup window and this menuitem still
    stay show. Thanks for your help.
    ==============================================================
    public class TestSimplePopup extends JFrame{
    JPopupMenu popupMenu;
    public TestSimplePopup() {
    super();
    //create popupmenu.
    popupMenu = new JPopupMenu();
    popupMenu.add( new JMenuItem("delete this link"));
    popupMenu.add( new JMenuItem("go to this link"));
    //create menubar.
    JMenuBar menuBar = new JMenuBar();
    //create favoritemenu.
    JMenu favoriteMenu = new JMenu("Favorite");
    JMenuItem link1 = new JMenuItem("http://java.sun.com");
    link1.addMouseListener(new MouseAdapter(){
    public void mousePressed(MouseEvent e) {
    if( SwingUtilities.isRightMouseButton(e) ){
    //right-click
    popupMenu.show(e.getComponent(), e.getX(), e.getY());
    } else {
    System.out.println( "left click=" + e.getSource() );
    favoriteMenu.add( link1 );
    menuBar.add( favoriteMenu );
    setJMenuBar( menuBar );
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);
    show();
    public static void main(String[] args) {
    new TestSimplePopup();
    ==============================================================

    First:
    please use code-tags when posting code. You should now this (its your 9th post after all).
    Second:
    I believe the NullPointerException is thrown because the popupMenu itself does not have a Window ancestor (I debugged your code). How to set the ancestor of your popupMenu to your JFrame I am not sure. JFrame has an add(PopupMenu) but not add(JPopupMenu).
    Perhaps someone else can help you further.

  • Sub-Menus are displaying away from their parent Menu for first time.

    Hi All,
    I have a problem with sub-menus display location. In my application, I have a JPopupMenu to which several sub-menus (*JMenu*) are added. All the JMenuItems inside JMenu are having an Icon (Image) along with menu item title. I am providing a facility to change the font size of Menu Item names as well as the ImageIcon size dynamically through a dialog box. When the size is changed to larger value than the existing, the menus as well as submenus are getting displayed correctly. But when I change the size of ImageIcon and the font to smaller value than the existing one, then the submenus are getting displayed away from their parent menu for the first time. The location of sub menu display is matching with the location when their size was larger. This problem appears only for the first display of sub menus after their sizes are changed. For the successive display, the locating is resetting automatically to correct location.
    So can anybody help me out about how to display submenus at correct location irrespective of font and image size changes for the first time also? Is there any event which gets fired when we change the font size or ImageIcon sizes? Is there any specific method to refresh the menu sizes if any of such properties (such as font size, ImageIcon size) are changed?
    If you need any additional information, feel free to ask.

    Below is the sample code for the query I placed. Steps to reproduce the problem are:
    1. Click on "Increase Font" button.
    2. Generate the popup at the right side corner of the screen (using right mouse click) such that the sub menu of edit should appear at left side of "Edit" option.
    3. Click on "Decrease Font" button.
    4. Generate the popup at the right side corner of the screen (using right mouse click) such that the sub menu of edit should appear at left side of "Edit" option.
    You will see that sub menu of edit menu is displayed away from the popup for the first time. The sub menu location matches with previous location when its font size was larger. Location resets automatically for the next successive displays.
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JPopupMenu;
    public class JPopupDemo implements ActionListener {
      public static Font newFont=new Font("Times New Roman", Font.BOLD,24);
      JFrame frame = null;
      JPopupMenu popupMenu = null;
      JMenuItem fileMenu = null;
      JMenu editMenu = null;
      JMenuItem cutMenuItem = null;
      JMenuItem copyMenuItem = null;
      JMenuItem pasteMenuItem = null;
      JMenuItem findMenuItem = null;
        JPopupDemo(){
        frame = new JFrame("Popup Example");     
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        popupMenu = new JPopupMenu();
        fileMenu = new JMenuItem("File");
        editMenu = new JMenu("Edit");
        cutMenuItem = new JMenuItem("Cut");
        editMenu.add(cutMenuItem);
        copyMenuItem = new JMenuItem("Copy");
        editMenu.add(copyMenuItem);
        pasteMenuItem = new JMenuItem("Paste");
        pasteMenuItem.setEnabled(false);
        editMenu.add(pasteMenuItem);
        editMenu.addSeparator();
        findMenuItem = new JMenuItem("Find");
        editMenu.add(findMenuItem);
        popupMenu.add(fileMenu);
        popupMenu.add(editMenu);
        MouseListener mouseListener = new JPopupMenuShower(popupMenu);
        frame.addMouseListener(mouseListener);
        //frame.setSize(350, 250);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dim = toolkit.getScreenSize();
        frame.setSize(dim.width,dim.height-100);
        JButton incrButton = new JButton("Increase Size");
        incrButton.setActionCommand("IncreaseSize");
        incrButton.addActionListener(this);
        JButton decrButton = new JButton("Decrease Size");
        decrButton.setActionCommand("DecreaseSize");
        decrButton.addActionListener(this);
        Container cp = frame.getContentPane();
        cp.setLayout(new BorderLayout());
        JPanel jp = new JPanel();
        jp.add(incrButton);
        jp.add(decrButton);
        cp.add(jp,BorderLayout.SOUTH);
        frame.setVisible(true);
    public static void main(String args[]) {
         JPopupDemo demo = new JPopupDemo();
      public void actionPerformed(ActionEvent ae)
            if (ae.getActionCommand().equals("IncreaseSize"))
                   newFont = new Font("Times New Roman", Font.BOLD,48);
                   setNewFont();
              else if (ae.getActionCommand().equals("DecreaseSize"))
                   newFont = new Font("Times New Roman", Font.BOLD,12);
                   setNewFont();
       public void setNewFont()
            popupMenu.setFont(newFont);
            fileMenu.setFont(newFont);
            editMenu.setFont(newFont);
            cutMenuItem.setFont(newFont);
            copyMenuItem.setFont(newFont);
            pasteMenuItem.setFont(newFont);
            findMenuItem.setFont(newFont);
    class JPopupMenuShower extends MouseAdapter {
      private JPopupMenu popup;
      public JPopupMenuShower(JPopupMenu popup) {
        this.popup = popup;
      private void showIfPopupTrigger(MouseEvent mouseEvent) {
        if (popup.isPopupTrigger(mouseEvent)) {
          popup.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent
              .getY());
      public void mousePressed(MouseEvent mouseEvent) {
        showIfPopupTrigger(mouseEvent);
      public void mouseReleased(MouseEvent mouseEvent) {
        showIfPopupTrigger(mouseEvent);
    }Edited by: VPKVL on Aug 4, 2008 1:18 AM

  • Look & feel of popupmenu doesn't change

    Hello,
    in my application I implemented the possibility to change the L&F of the app. This works fine with all my Components, like Menus, Toolbar, Panel etc. The only thing that does not change it's L&F is a popupmenu. It's an instance of JPopupMenu with 3 JMenuItems and it's invoked by a panel.
    Do I have to add any functionality by myself? or is this normal?
    For all the other Components I didn't do anything, it works automatically just by calling
    UIManager.setLookAndFeel(lnfName);
    SwingUtilities.updateComponentTreeUI(this);
    in the main frame. All Components are childs of that JFrame-based class.
    Thanks in advance for any hint
    Herby

    Hi,
    try addingthis.pack();Phil

  • PopupMenu does not display

    Pleaase help me. popup menu doesn't display.
    Thanks.
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.util.Hashtable;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.applet.Applet;
    public class Combox extends JApplet{
         private JPopupMenu popup;
      public void init(){
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        initComponents();
            } catch (Exception ex) {
                ex.printStackTrace();
         private void initComponents() {
            jPanel1 = new JPanel();
            jPanel1.setLayout(new java.awt.GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(1,1,1,1);
            gbc.weightx = 1.0;
            popup = new JPopupMenu("Shift Choice");
            JMenuItem item;
            popup.add(item = new JMenuItem("Shift Left"));
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            jPanel1.add(popup, gbc);
            gbc.gridx = 1;
            Container cp = getContentPane(); 
            cp.add(jPanel1,"North");
         }

    Okay, now it works well.
    But When I embed the applet into a web page, one more item displays.
    Java Applet Window // Why it shows.My code
    public class Combox extends JApplet{
            private JPopupMenu popupmenu;
            private String s1 = "Shift Left";
            private String s2 = "Shift Right";
            private String s3 = "Shift Up";
            private String s4 = "Shift Down";
      public void init(){
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        initComponents();
            } catch (Exception ex) {
                ex.printStackTrace();
         private void initComponents() {
            popupmenu = new JPopupMenu();
            JMenuItem itemShiftLeft  = new JMenuItem(s1);
            JMenuItem itemShiftRight = new JMenuItem(s2);
            JMenuItem itemShiftUp    = new JMenuItem(s3);
            JMenuItem itemShiftDown  = new JMenuItem(s4);
            ActionListener actionListener = new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
              JMenuItem source = (JMenuItem)(e.getSource());       
                    String s = source.getText();
                    if(s.equals(s1))
                        txy[0] += -50;
                    else if(s.equals(s2))
                        txy[0] += 50;
                    else if(s.equals(s3))
                        txy[1] += -50;
                    else if(s.equals(s4))
                        txy[1] += 50;
                    graphicPanel.sett(txy);
            popupmenu.add(itemShiftLeft);
            popupmenu.addSeparator();
            itemShiftLeft.addActionListener(actionListener);
            popupmenu.add(itemShiftRight);
            popupmenu.addSeparator();
            itemShiftRight.addActionListener(actionListener);
            popupmenu.add(itemShiftUp);
            popupmenu.addSeparator();
            itemShiftUp.addActionListener(actionListener);
            popupmenu.add(itemShiftDown);
            popupmenu.addSeparator();
            itemShiftDown.addActionListener(actionListener);      
            addMouseListener(
                    new MouseAdapter(){
                public void mousePressed(MouseEvent event){
                    processMouseEvent(event);
            public void mouseReleased(MouseEvent event){
                processMouseEvent(event);
            public void processMouseEvent( MouseEvent event ){
              if( event.isPopupTrigger() ){
                   popupmenu.show( event.getComponent(),
                             event.getX(), event.getY() );
      

  • Use a PopUpMenu as ToolTip

    Hi,
    First, I want to know if is possible to make a PopUpMenu look like a Tooltip?
    And Secondly, I need to add blank JmenuItems that doesn't responds to the mouse click, it is Possible?
    If this two things are possible I could use the popUpMenu as Tooltip using aggregation in the MouseAdapter. Thanks in advance.
    PS. I need to calla method if a line of text in the tooltip is clicked, this is why I'm trying to use the popUpMenu instead of the default Tooltip. Thanks
    Regards,
    Miguel
    Edited by: miguelNieves0714 on Apr 18, 2009 8:53 AM

    camickr,
    You just save my Life!!!! Man Thank you very much. I haven't incorporate the code to my project, but I know this is what I was searching for. Man I really Thank You for this. I don't know how can I pay you back, but if you need something or you are comming to Puerto Rico I'll be glad to welcome you here, my email is [email protected] This simple code will help a lot. These forums rocks!!!! Thank God Good People that want to help others exists. Thank You camickr.
    PS. I know you told me that this was already explained in the forums, but i did not manage to find this one. I really Thank You for directing me to the right URL. THANK YOU!!!!!!!!!!!!!!! AND GOD BLESS YOU
    Regards,
    Miguel A.

  • Create a PopupMenu when right click onto an item of JComboBox

    How do I make so that, a popupmenu appear only when I right click onto a item of JComboBox. What I have right now is showing a PopupMenu whenever I right click on the frame.
    I got another question to ask if you guys dont mind. How do I set the ComboBox to scroll horizontally. Right now I set the preferredSize of the ComboBox so if the item's names are too long, it will be cut off. Can I set it so that I can scroll horizontally to see the rest of the item's name?

    My English is very poor, so it's hard to explain...
    3.
    // This is just an example code and has not been tested.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    public class ComboRightClickTest{
      public JComponent makeUI(final JFrame frame) {
        frame.setGlassPane(new LockingGlassPane());
        String[] items = {"test1", "test2", "test3"};
        JComboBox combo = new JComboBox(items);
        combo.setUI(new BasicComboBoxUI() {
          protected ComboPopup createPopup() {
            return new BasicComboPopup( comboBox ) {
              protected JList createList() {
                return new JList( comboBox.getModel() ) {
                  public void processMouseEvent(MouseEvent e)  {
                    if(e.isPopupTrigger()) {
                      String s = getSelectedValue().toString();
                      frame.getGlassPane().setVisible(true);
                      final JPopupMenu m = new JPopupMenu();
                      final JMenuItem i = new JMenuItem(
                          new AbstractAction("del:"+s) {
                        public void actionPerformed(ActionEvent ae) {
                          comboBox.removeItemAt(getSelectedIndex());
                          frame.getGlassPane().setVisible(false);
                          m.setVisible(false);
                      i.addMouseListener(new MouseAdapter() {
                        public void mouseEntered(MouseEvent me) {
                          i.setBackground(getSelectionBackground());
                        public void mouseExited(MouseEvent me) {
                          i.setBackground(getBackground());
                      m.add(i);
                      Point p = e.getPoint();
                      SwingUtilities.convertPointToScreen(p, this);
                      m.show(null, p.x, p.y);
                      return;
                    super.processMouseEvent(e);
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        p.add(combo, BorderLayout.NORTH);
        p.setPreferredSize(new Dimension(320, 100));
        return p;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { createAndShowGUI(); }
      public static void createAndShowGUI() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.getContentPane().add(new ComboRightClickTest().makeUI(f));
        f.setResizable(false); //XXX
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    class LockingGlassPane extends JComponent {
      public LockingGlassPane() {
        setOpaque(false);
      @Override public void setVisible(boolean isVisible) {
        boolean oldVisible = isVisible();
        super.setVisible(isVisible);
        JRootPane rootPane = SwingUtilities.getRootPane(this);
        if(rootPane!=null && isVisible()!=oldVisible) {
          rootPane.getLayeredPane().setVisible(!isVisible);
      @Override public void paintComponent(Graphics g) {
        JRootPane rootPane = SwingUtilities.getRootPane(this);
        if(rootPane!=null) {
          http://weblogs.java.net/blog/alexfromsun/archive/2008/01/
          rootPane.getLayeredPane().print(g);
        super.paintComponent(g);
    }

  • JPopupMenu with multiline JMenuItem ?

    Hi there.
    Is it possible to do something like the subject says, a JPopupMenu with multiline JMenuItem's, without using html? I would like to create a JMenuItem with a MultiLineLabel as the argument instead of a String. I'm trying to do this because if i add the MultiLineLabel directly to the JPopupMenu, it displays as i want, but i loose the behaviour inherent to a JMenuItem, the highlighted index, etc.. Any help would be appreciated.

    Here's a workaround:
    JPopupMenu popupMenu = new JPopupMenu();
    // Workaround to stop first menu item being selected
    JMenuItem dummyItem = popupMenu.add(new JMenuItem());
    dummyItem.setPreferredSize(new Dimension(0, 0));
    popupMenu.add("Item 1");
    popupMenu.add("Item 2");
    popupMenu.add("Item 3");
    It works for me!

  • Why all JMenuItem's of JPopupMenu perform the same action?

    Why all JMenuItem's of JPopupMenu perform the same action?
    I trying to do something similar to what there is in JBuilder where you right click a method or a class - you get a popUpMenu and if you choose the
    "Browse Symbol" JBuilder browses to that method/class.
    I'm trying to do the same and to browse to some class of mine (not a java class). But there's a problem.
    This is my code : -
    OMClass desiredClass = event.getNavigationClass();
    if(desiredClass instanceof OMComplexClass) {
    Set classSet = desiredClass.getSimpleClasses();
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuItem = null;
    menu.add("Browse to :");
    menu.addSeparator();
    Iterator it = classSet.iterator();
    for(; it.hasNext(); ) {
    OMConcept concept = (OMConcept)it.next();
    menuItem = new JMenuItem(concept.getName());
    menuItem.addActionListener(new NavigateToComplexClass(concept));
    menu.add(menuItem);
    menu.show((JComponent)(event.getMouseEvent().getSource()), getX(), event.getMouseEvent().getY());
    ComplexClass is build of SimpleClasses - so if I want to browse to complex class I ask the user by a JPopupMenu what specific SimpleClass he would like to browse to. My ActionListener is a NavigateToComplexClass class - and hewe is the code : -
    public class NavigateToComplexClass implements ActionListener, ItemListener {
    private static OMClass classToShow = null;
    GUI_Location currentLocation = null;
    public NavigateToComplexClass(OMConcept desiredClass) {
    classToShow = (OMClass)desiredClass;
    public void actionPerformed(ActionEvent evt) {
    currentLocation = frame.fillGUI_Location();
    frame.getProject().getHistoryManager().updateHistory(currentLocation);
    if(classToShow == null) {
    return;
    frame.getClassDisplay().getTabbedPane().setSelectedIndex(1);// 1 - parameeter : Property tab.
    frame.getConceptViewPanel().selectConcept((OMConcept)classToShow);
    public void itemStateChanged(ItemEvent e) {
    The problem is that no matter what JMenuItem I select and press it's navigating to the same simpleClass like if I have a
    b
    c
    no matter what I'll press I'll always goto a (or b or c but always the same)

    hi,
    for your actionlistener all those items are more or less the same. when browsing to them you have to give them different names or better different actioncommands.
    regards

  • Add popupMenu to the elements of a jToolBar

    Hi all,
    I'm trying to add a popupMenu to the images that I have in a jToolBar. So my idea is to show the popupMenu when the user clicks with the secondary mouse button in one of the images. When the user clicks with the primary mouse button the application does another action. I have the ThumbnailAction class that implements it:
    private class ThumbnailAction extends AbstractAction
    *The icon if the full image we want to display.
    private Icon displayPhoto;
    private JPopupMenu jPopupMenu1 = new JPopupMenu();
    private JPanel topPanel;
         private     JPopupMenu popupMenu;
    * @param Icon - The full size photo to show in the button.
    * @param Icon - The thumbnail to show in the button.
    * @param String - The descriptioon of the icon.
    public ThumbnailAction(Icon photo, Icon thumb, String desc){
    topPanel = new JPanel();
              topPanel.setLayout( null );
              getContentPane().add( topPanel );
              // Create some menu items for the popup
              JMenuItem menuFileNew = new JMenuItem( "New" );
              JMenuItem menuFileOpen = new JMenuItem( "Open..." );
              JMenuItem menuFileSave = new JMenuItem( "Save" );
              JMenuItem menuFileSaveAs = new JMenuItem( "Save As..." );
              JMenuItem menuFileExit = new JMenuItem( "Exit" );
              // Create a popup menu
              popupMenu = new JPopupMenu( "Menu" );
              popupMenu.add( menuFileNew );
              popupMenu.add( menuFileOpen );
              popupMenu.add( menuFileSave );
              popupMenu.add( menuFileSaveAs );
              popupMenu.add( menuFileExit );
              topPanel.add( popupMenu );
              // Action and mouse listener support
              enableEvents( AWTEvent.MOUSE_EVENT_MASK );
              menuFileNew.addActionListener( this );
              menuFileOpen.addActionListener( this );
              menuFileSave.addActionListener( this );
              menuFileSaveAs.addActionListener( this );
              menuFileExit.addActionListener( this );
    // displayPhoto = photo;
    // The short description becomes the tooltip of a button.
    putValue(SHORT_DESCRIPTION, desc);
    // The LARGE_ICON_KEY is the key for setting the
    // icon when an Action is applied to a button.
    putValue(LARGE_ICON_KEY, thumb);
    public void processMouseEvent( MouseEvent event )
    System.out.println("entra aki cony!");
              if( event.isPopupTrigger() )
                   System.out.println("is popup!");//popupMenu.show( event.getComponent(), event.getX(), event.getY() );
              this.processMouseEvent( event );
    * Shows the full image in the main area and sets the application title.
    public void actionPerformed(ActionEvent e) {
    System.out.println("hay evento");
    photographLabel.setIcon(displayPhoto);
    /* Executable ex = null;
    try {
    ex.openDocument("C:/Documents and Settings/Administrador/iText/src/com/lowagie/tools/PDF's/pdf3.pdf");
    } catch (IOException exc) {
    exc.printStackTrace();
    StringTokenizer st = new StringTokenizer (getValue(SHORT_DESCRIPTION).toString());
    actualPDF =st.nextToken(". ");
    actualPDF += ".pdf";
    setTitle("Selected document: " + actualPDF);
    The problem I have is that the app never goes to processMouseEvent(), I think I have problems with the inheritance or sth else. It would be thankful if somebody can help me, please!!!
    Thanks in advance!!!

    If you want your video to play on anywhere then you don't want Flash. You should be able to use a simple html5 page to play your video and then redirect the user to a new page, or display a new div to get to the form. Here's a good discussion of doing that sort of thing: http://help.videojs.com/discussions/questions/509-videojs-and-passing-an-event-at-the-end- of-the-video You can also look at the regular html video dom reference: http://www.w3schools.com/tags/av_prop_ended.asp

  • Keeping toolbar button pressed when displaying a popupmenu beneath it

    I have written a custom widget - the drop down button. We can find examples of this widget all over the place - for eg. IE back button, Mail button, JBuilder run button etc.
    The problem is this:
    when the arrow button is pressed I display the popupmenu. Now, I need the button to hold its "pressed" state and appear accordingly while the popup menu is visible.
              arrowButton.addMouseListener(new MouseAdapter(){
                   public void mousePressed(MouseEvent e)
                        showPopup();
    Any ideas?

    Here is your SSCE. Feel free to compile and run it. It will bring up a JFrame with toolbar buttons that show what I was talking about.
    Note that the non popup buttons appear pressed when the mouse is kept pressed on them. Not so for the popup ones.
    I cannot use an actionListener instead of mouse listener while displaying the popups because I need the popup to be visible with the first press of the mouse, not the first release (just like a combo-box)
    import java.awt.BorderLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.JToggleButton;
    import javax.swing.JToolBar;
    import javax.swing.UIManager;
    public class Main3 {
         static JFrame frame = new JFrame("Test");
         static JToolBar toolBar = null;
         * @param args
         public static void main(String[] args)
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                   toolBar = new JToolBar();
                   toolBar.setFloatable(false);
                   toolBar.setRollover(true);
                   initToolBar();
                   frame.getContentPane().add(toolBar, BorderLayout.NORTH);
                   frame.pack();
                   frame.setSize(800,600);
                   frame.setVisible(true);
              catch (Exception ex)
                   ex.printStackTrace();
         private static void initToolBar()
              final JPopupMenu popupMenu = new JPopupMenu();
              popupMenu.add(new JMenuItem("hello"));
              popupMenu.add(new JMenuItem("world"));
              final JButton button = new JButton("Popup JButton");
              button.addMouseListener(new MouseAdapter(){
                   public void mousePressed(MouseEvent e)
                        popupMenu.show(button,0,button.getHeight());
              final JToggleButton toggleButton = new JToggleButton("Popup JToggleButton");
              toggleButton.addMouseListener(new MouseAdapter(){
                   public void mousePressed(MouseEvent e)
                        popupMenu.show(toggleButton,0,toggleButton.getHeight());
              final JButton nonPopupButton = new JButton("No Popup JButton");
              nonPopupButton.addMouseListener(new MouseAdapter(){
                   public void mousePressed(MouseEvent e)
                        System.out.println("Non popup button pressed");
              final JToggleButton nonPopupToggleButton = new JToggleButton("No Popup JToggleButton");
              nonPopupToggleButton.addMouseListener(new MouseAdapter(){
                   public void mousePressed(MouseEvent e)
                        System.out.println("Non popup toggle button pressed");
              toolBar.add(button);
              toolBar.addSeparator();
              toolBar.add(toggleButton);
              toolBar.addSeparator();
              toolBar.add(nonPopupButton);
              toolBar.addSeparator();
              toolBar.add(nonPopupToggleButton);
    }

  • JPopupMenu - setSelected (JMenuItem)

    Hi
    I have a popup menu with a number of menu items which I add to the popupMenu. I call setSelected with one of them (not the first added) and then show. But it is always the first item that is shown as being selected, even though when I call getSelectionModel().getSelectedIndex it returns the index of the item I set to be selected.
    I can see that others have had similar problems, but haven't been able to find anyone that could answer them.

    Why do you want the menu item selected?
    This works, but may not fully answer your question. ***************************************************************************************************
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.BorderLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.UIManager;
    public class PopupTest extends JFrame implements ActionListener
    public static void main( String[] args )
    PopupTest test = new PopupTest();
    test.pack();
    test.show();
    private JPopupMenu popup;
    private JMenuItem menuItem1;
    private JMenuItem menuItem2;
    public PopupTest()
    try
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch( Exception e )
    popup = new JPopupMenu();
    menuItem1 = new JMenuItem( "Item 1");
    menuItem1.setActionCommand( "Item 1");
    menuItem1.addActionListener( this );
    menuItem2 = new JMenuItem( "Item 2");
    menuItem2.setActionCommand( "Item 2");
    menuItem2.addActionListener( this );
    popup.add( menuItem1 );
    popup.add( menuItem2 );
    JButton button = new JButton("Button 1");
    button.setActionCommand("Button 1");
    button.addActionListener( this );
    this.getContentPane().add( button );
    button = new JButton("Button 2");
    button.setActionCommand("Button 2");
    button.addActionListener( this );
    this.getContentPane().add( button, BorderLayout.EAST );
    public void actionPerformed(ActionEvent e)
              System.out.println(e.getActionCommand());
    popup.show( this, 0,0 );
    if( e.getActionCommand().equals( "Button 1" ) )
    popup.setSelected( menuItem1 );
    menuItem1.setArmed( true );
    menuItem2.setArmed( false );
    else if( e.getActionCommand().equals( "Button 2" ) )
    popup.setSelected( menuItem2 );
    menuItem1.setArmed( false );
    menuItem2.setArmed( true );

  • Wxpython, popupmenu and UnicodeDecodeError

    Hey,
    I'm working on a small wxPython app but I'm getting a weird decoding error and I don't know where it would be coming from. When I run it the window loads fine but rightclicking on the tray icon  dumps this to the terminal (the app doesn't crash):
    File "btproximity.py", line 46, in PopupMenu
        self.PopupMenu(menu)
      File "btproximity.py", line 46, in PopupMenu
        self.PopupMenu(menu)
      File "btproximity.py", line 46, in PopupMenu
        self.PopupMenu(menu)
      File "btproximity.py", line 46, in PopupMenu
        self.PopupMenu(menu)
      File "btproximity.py", line 43, in PopupMenu
        menu.Append(self.menushow, "Show Info")
      File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py", line 10202, in Append
        return _core_.Menu_Append(*args, **kwargs)
      File "/usr/lib/python2.4/encodings/iso8859_1.py", line 22, in decode
        return codecs.charmap_decode(input,errors,decoding_map)
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x68 in position 1: character maps to <undefined>
    That first bit is repeated a crapload of times. Here is the code. If anyone has any ideas I'd really appreciate it. It's a bit over my head, I've Googled and tried making manual calls to the codecs module to see if I can figure out what's causing it but no go. I recently changed my locale from en_US to en_AU but running the script with --locale=en_US didn't make any difference

    I'm having a very similar problem. I create a JPopupMenu (as a context, right click, menu) and JMenu on a JMenuBar with the exact same JMenuItems. I bring up the JMenu and the items are all there. I bring up my JPopupMenu and all items are there but when I go back to the JMenu on my JMenuBar all the items have been removed.
    This seems like a bug to me. Any ideas?

  • Disabled JMenuItem doesn show animated gif

    Hi there
    I would like to have a popup menu with actions that are enabled after they have finished with some background task taking some time. Basically this works fine for the enabling action on a shown popup. However, adding an animated gif as the icon or disabled icon does not show it in disabled state. In enabled state it works perfect. Please have a try with the sample code. You should see the disabled item for 2 secs and the icon is not showing up. After being enabled, it does. Invoking the menu again shows the animated gif in its last state left, but not moving any more.
    I guess, repaints are not done appropriately in disabled state... Any ideas how to solve that would be highly appreciated :-)
    Actually I used the icon at http://mentalized.net/activity-indicators/indicators/pascal_germroth/indicator.white.gif
    Cheers
    Daniel
    public class Main
      public static void main(String[] args)
        final JFrame frame = new JFrame();
        frame.addMouseListener(new MouseAdapter()
          public void mousePressed(final MouseEvent e)
            final JPopupMenu popup = new JPopupMenu();
            popup.add(new JMenuItem("Open..."));
            popup.add(new JMenuItem("Close"));
            final JMenuItem action = new JMenuItem("Long loading until enabled");
            action.setIcon(new ImageIcon("C:/spinner.gif"));
            action.setDisabledIcon(new ImageIcon("C:/spinner.gif"));
            popup.add(action).setEnabled(false);
            popup.show(e.getComponent(), e.getX(), e.getY());
            SwingUtilities.invokeLater(new Runnable()
              public void run()
                try
                  Thread.sleep(2000);
                  action.setEnabled(true);
                catch (InterruptedException e1)
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);
        frame.setVisible(true);
    }Edited by: daniel.frey on Apr 22, 2009 7:50 AM

    The problem is that you are causing the EDT to sleep, which means the GUI can't repaint itself. Read the section from the Swing tutorial on Concurrency to understand what is happening.

  • Dynamic PHTMLB PopupMenu

    Anyone have any idea why I can't get my popupmenu to work?  I have two sets of data, one we'll call code groups and the other group items.  I simply want the group items to be a submenu of their group.  I can get exactly one group item to slide out, and it looks strange in a large font.
    Anyone see something I don't? 
    method ZFILL_OTEIL_POPUP .
    data: wa_popup like line of oteilgroup,
          lv_group type zqpgt_tab,
          lv_item  type zqpct_tab,
          lv_text type string,
          separator(3) value ' - '.
    field-symbols: <group> type zqpgt,
                   <item>  type zqpct.
    lv_group = me->zget_group_codes( p_katalogart = 'B' ).
    lv_item = me->zget_item_codes( p_katalogart = 'B' ).
    data: id type string,
          index type string.
    loop at lv_group assigning <group>.
      clear wa_popup.
      clear id.
        refresh oteilitem.
      move sy-tabix to index.
      concatenate 'oteilSubPopup' index into id.
      concatenate <group>-codegruppe <group>-kurztext into lv_text
                  separated by separator.
      wa_popup-menuitemid = 'oteilPopup'.
      wa_popup-submenuid  = id.
      wa_popup-text = lv_text.
    wa_popup-cancheck = 'X'.
      wa_popup-enabled  = 'X'.
      append wa_popup to oteilgroup.
      loop at lv_item assigning <item>
           where codegruppe = <group>-codegruppe.
        clear wa_popup.
        concatenate <item>-code <item>-kurztext into lv_text
                    separated by separator.
        wa_popup-menuitemid = id.
        wa_popup-text = lv_text.
       wa_popup-cancheck = 'X'.
        wa_popup-enabled  = 'X'.
        append wa_popup to oteilitem.
      endloop.
        append oteilitem to oteilitems. "deeply structured itab
    endloop.
    endmethod.
    LAYOUT
                    <td><htmlb:label for="object" text="Object Code"/></td>
                    <td><htmlb:inputField id="damage" value="//model/notif_fields.fecod" disabled="true"/>
                        <phtmlb:popupTrigger id="oteilTrigger"
                                             popupMenuId="oteilPopup"
                                             isInteractive="true" >
                        <htmlb:image src="s_b_hint.gif" />
                        </phtmlb:popupTrigger>
                        <phtmlb:popupMenu id="oteilPopup"
                                          firstVisibleItemIndex="1"
                                          maxVisibleItems="25"
                                          items="<%=oteilgroup%>">
                        </phtmlb:popupMenu>
    <% data: wa_item type PHTMLB_POPUPMENUITEMS,
             id type string,
             index type string. %>
    <% loop at oteilitems into wa_item.
           move sy-tabix to index.
           concatenate 'oteilSubPopup' index into id. %>
           <phtmlb:popupMenu id="<%= id %>"
                             onSelect="myOteil"
                             firstVisibleItemIndex="1"
                             maxVisibleItems="25"
                             items="<%= wa_item %>">
           </phtmlb:popupMenu>
           <% refresh wa_item. %>
    <% endloop. %>

    Hi Thomas,
             Thanks for the reply.
             As you have said there are no background or MouseOver color for popupMenu. I am using a workaround for this by putting the popMenuItems in an html table and then changing the above said attributes for the individual cells. This works fine in normal menu but no effect when used with popupMenu. If you want I can send you the code but that will be possible tomorrow.
    Regards
    PRAFUL

Maybe you are looking for

  • When I try to update my iPod Touch, I get an error message regarding my network connection, and it will not update. Any suggestions?

    When I try to update my iPod Touch, I get an error message saying "The iPod Software update server could not be contacted. Make sure your network settings are correct and your network connection is active, or try again later." Has anyone else had tha

  • Nokia 6500 classic is being an Pain!

    I've had a Nokia 6500 classic for a few months now and the main charger wont charge the phone. But on top of this the USB charger only charges the phone to about half way and then stops. Any ideas on how to get this phone charged, the only options I

  • No equalizer on the Lumia 800?

    It looks like the 800 doesn't have an equalizer.  Are there plans to add it in an update or as an additional download? It's a sad omission for a phone that's advertised with decent headphones.  Thanks!  

  • Stock ledger with WBS element

    Dear experts , I need a stock ledger , ( opening , receipt , issue , closing )  , just like in MB%B , wherein i should have the WBS element displayed. Pls help Regards Anis

  • Load XML and edit

    Hi I am new to Flex and AS3 but I have some experience with XML, XSLT, XPATH, VB etc.. I am having trouble just loading the XML. How do I load an external XML file so I can edit it? This is what I have so far: <mx:Script> <![CDATA[ var myxml = 'xml/r