Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:08:24+00:00 2026-06-03T03:08:24+00:00

How can I do an ActionListener for each button in the list? I’m using

  • 0

How can I do an ActionListener for each button in the list? I’m using JGraphMenu & want to display an alert for each item.

Here is my code:

public static void main(String[] args){
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
List<String> MenuItem = new ArrayList<String>();
MenuItem.add("Choose The XML File");
MenuItem.add("Generate the tree");
MenuItem.add("Generate the latex code");
MenuItem.add("Generate automata");
List<ActionListener> listeners = new ArrayList<ActionListener();
for(int i=0; i<4; i++){
listeners.add(null);
}

JGraphMenu menu = new JGraphMenu(
ConstantesStyles.NOIR,
JGraphMenu.VERTICAL, 
MenuItem, listeners
);

JPanel panel = new JPanel();
panel.add(menu);
panel.setSize(50, 100);
f.add(panel, BorderLayout.WEST);
f.setSize(500, 400);
f.setLocationRelativeTo(null);
        f.setVisible(true);

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:08:26+00:00Added an answer on June 3, 2026 at 3:08 am

    Instead of adding nulls to the ActionListener‘s list, add listeners (in my example, the same listener, but you get the idea):

    List<ActionListener> listeners = new ArrayList<ActionListener()>;
    ActionListener listener = new ActionListener() {
        @Override void actionPerformed(ActionEvent e) {
            // do something
        }
    };
    for(int i=0; i<4; i++){
        listeners.add(listener);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an ActionListener to update a JList whenever an item is selected. jComboBox.addActionListener(new
I'm new at using actionListener and mouselistner . I want to track the Mouse
Can anyone point me in the right direct to this? I want the actionlistener
Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
How can I give my JMenuItem s names that the ActionListener attached to them
I need to activate a JButton ActionListener within a JDialog so I can do
In trying to write more testable Java code, I have been using the Model-View-Presenter
Can you help me out here? A really simple problem but I just can't
I need to create some JSpinner controls where I can detect the button presses,
I'm using a thread to display an animation with a sprite. Explosion e2 =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.