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 7497519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:07:51+00:00 2026-05-29T19:07:51+00:00

I am not sure what i am doing wrong here, or even how to

  • 0

I am not sure what i am doing wrong here, or even how to refine a search to cover this. Searching for Dynamic menu changes returns a ton of information but i am not finding what specifically i am looking for. I want to dynamically add sub menu’s based on the current contents of an array, and change the tool tip for the menu. As proof of concept i just attempted to alter the tool tip inside the menu items actionListener. I think i am running into a scope issue with the DeleteTask name. When i try to use it inside the handler, i get an error telling me to use Final. When i do that i get a ‘symbol not found’ error. It has been a few months since i used Java to code, so i might have slipped on a concept or two.

JMenuItem DeleteTask = new JMenuItem("Delete Task");
DeleteTask.setMnemonic(KeyEvent.VK_D);
DeleteTask.setToolTipText("Delete a Task");
DeleteTask.addActionListener(new ActionListener() {

 public void actionPerformed(ActionEvent event) {
  if(testCondition)
  {
    DeleteTask.setToolTipText("Changed Tool Tip");                
  }
  else  //testing
  {

    DeleteTask.setToolTipText("Delete a Task"); 
  }

}
});

Could anyone explain why this method wont let me change the tool tip? What method should i be using to make these changes? Any search tips would be appreciated greatly. Thank you.

  • 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-05-29T19:07:52+00:00Added an answer on May 29, 2026 at 7:07 pm

    not sure what happened, there must be another issue in your code, but everything could be …. only speculations, my SSCCE

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    
    public class ActionExample {
    
        private boolean testCondition = false;
        private JMenuItem DeleteTask = new JMenuItem("Delete Task");
    
        public ActionExample() {
            Action sample = new SampleAction();
            DeleteTask.setMnemonic(KeyEvent.VK_D);
            DeleteTask.setToolTipText("Delete a Task");
            DeleteTask.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent event) {
                    if (testCondition) {
                        testCondition = false;
                        DeleteTask.setToolTipText("Changed Tool Tip");
                    } else {
                        testCondition = true;
                        DeleteTask.setToolTipText("Delete a Task");
                    }
                }
            });
            JMenu menu = new JMenu("Menu");
            menu.setMnemonic(KeyEvent.VK_M);
            menu.add(sample);
            menu.add(DeleteTask);
            menu.addMenuListener(new SampleMenuListener());
            JToolBar tb = new JToolBar();
            tb.add(sample);
            JTextField field = new JTextField(10);
            field.setAction(sample);
            JFrame f = new JFrame("ActionExample");
            JMenuBar mb = new JMenuBar();
            mb.add(menu);
            f.setJMenuBar(mb);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(tb, BorderLayout.NORTH);
            f.getContentPane().add(field, BorderLayout.SOUTH);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    ActionExample actionExample = new ActionExample();
                }
            });
        }
    }
    
    class SampleMenuListener implements MenuListener {
    
        @Override
        public void menuSelected(MenuEvent e) {
            System.out.println("menuSelected");
        }
    
        @Override
        public void menuDeselected(MenuEvent e) {
            System.out.println("menuDeselected");
        }
    
        @Override
        public void menuCanceled(MenuEvent e) {
            System.out.println("menuCanceled");
        }
    }
    
    class SampleAction extends AbstractAction {
    
        private static final long serialVersionUID = 1L;
    
        public SampleAction() {
            super("Sample");
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt S"));
            putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
            putValue(SHORT_DESCRIPTION, "Just a sample action");
        }
    
        @Override
        public void actionPerformed(ActionEvent evt) {
            System.out.println("sample...");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure what I am doing wrong here, not even sure if I
I know this probably really simple but Im not sure what im doing wrong...
I'm mot sure if I'm doing this wrong or not I don't know if
Not sure if I am doing this correctly or not. Here is my .js
I'm not sure if I'm doing something wrong here: I'm registering for Workspace notifications
I'm not sure what I'm doing wrong here. I have a generic class, which
Not sure what I'm doing wrong with .live() $(function(){ var wrapper = $('#trailer_wrapper'); var
I am not sure what I am doing wrong, It would be great if
I am not sure what I could be doing wrong that causes info level
I'm not sure what I am doing wrong, but the text for my JPanels

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.