Linux PupupMenu CheckboxMenuItem Bug

Discussion in 'Java' started by Rene Grothmann, Apr 11, 2007.

  1. Does anybody know how to resolve the following Linux problem? I am
    unable to get events from a checkbox item in a popup menu under Linux.
    The problem seems to be unknown to other Java versions. Of course,
    using JFC would resolve the problem, but I want to stay with AWT for
    some reasons.

    Thanks a lot foa any constructive answers.

    ---------------------------------

    import java.awt.*;
    import java.awt.event.*;

    public class PopupTest extends Frame
    implements ActionListener, ItemListener
    { PopupMenu PM;

    public PopupTest ()
    { super("Popup Test");
    setSize(500,500);
    setLocation(200,200);
    addWindowListener(new WindowAdapter ()
    { public void windowClosing (WindowEvent e)
    { System.exit(0);
    }
    });
    addMouseListener(new MouseAdapter ()
    { public void mouseClicked (MouseEvent e)
    { clicked(e);
    }
    });
    PM=new PopupMenu();

    MenuItem item1=new MenuItem("Item 1");
    PM.add(item1);
    item1.addActionListener(this);


    // buggy code?
    CheckboxMenuItem item2=new CheckboxMenuItem("Item 2");
    PM.add(item2);
    item2.addItemListener(this);
    item2.addActionListener(this);

    add(PM);

    }

    public void clicked (MouseEvent e)
    { PM.show(this,e.getX(),e.getY());
    }

    public static void main (String args[])
    { Frame f=new PopupTest();
    f.setVisible(true);
    }

    public void actionPerformed (ActionEvent e)
    { System.out.println(e);
    }

    public void itemStateChanged (ItemEvent e)
    { System.out.println(e);
    }
    }
     
    Rene Grothmann, Apr 11, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. U. George
    Replies:
    4
    Views:
    844
    U. George
    Aug 11, 2005
  2. Dieter Maurer
    Replies:
    0
    Views:
    263
    Dieter Maurer
    May 21, 2004
  3. Tim Peters
    Replies:
    1
    Views:
    350
    Dieter Maurer
    May 23, 2004
  4. Russell E. Owen

    directory bug on linux; workaround?

    Russell E. Owen, Jan 13, 2005, in forum: Python
    Replies:
    3
    Views:
    333
    Ewald R. de Wit
    Jan 17, 2005
  5. Krishna Chaitanya
    Replies:
    1
    Views:
    144
    Krishna Chaitanya
    Feb 27, 2009
Loading...

Share This Page