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.
not sure what happened, there must be another issue in your code, but everything could be …. only speculations, my SSCCE