Results 1 to 4 of 4
  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default JMenuItems with actionlistener of itemlistener?

    i can't seem to make my JMenuItems do something when they are clicked.

    is it done with an actionlistener like:
    Java Code:
    if(event.getSource()==JMenuItem1){
    JOptionPane.showMessagedialog(null, "");
    
    }
    or with an itemlistener?

  2. #2
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    263
    Rep Power
    2

    Default Re: JMenuItems with actionlistener of itemlistener?

    the code you have is not how action listeners are written, what you have written is usually the conditions inside an actionPerformed method that you have added all your components a listener to the GUI itself, and you use getSource() to identify which component had the event. I think you asked this before in a post and I sent you the the tutorial on how to write an action listener, you have not done this. How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

    you want an action listener on the JMenuItem, but it is best for you to read the tutorial to understand how it is done.

  3. #3
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: JMenuItems with actionlistener of itemlistener?

    i know how to write action listeners. i did it numerous times, but i can't get it work on a JMenuItem.

  4. #4
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    263
    Rep Power
    2

    Default Re: JMenuItems with actionlistener of itemlistener?

    then you shouldn't have any problem because it is the same as adding it on a JButton

Similar Threads

  1. Printing JMenuItems contnets
    By Mash in forum AWT / Swing
    Replies: 0
    Last Post: 04-26-2010, 08:37 PM
  2. ItemListener problem with JComboBox
    By al_Marshy_1981 in forum AWT / Swing
    Replies: 3
    Last Post: 04-16-2010, 10:24 PM
  3. JMenuItems and actions
    By Kligham in forum New To Java
    Replies: 5
    Last Post: 01-05-2010, 05:00 PM
  4. Demonstrating the ItemListener
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 04-23-2008, 08:25 PM
  5. How to use ItemListener for CheckBox class
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 04-23-2008, 08:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •