This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes how to change the icon of an menuitem's action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to change the icon of an menuitem Watch "how to change the icon of an menuitem New topic
Author

how to change the icon of an menuitem's action

Edu Cobi
Greenhorn

Joined: Jan 24, 2004
Posts: 9
Hello all,
I have created a menuitem using an action:
***************************************************
ImageIcon iconOff=new ImageIcon("onlineOff.gif");
actionOff=new AbstractAction("Connect/Disconnet",iconOff){
public void actionPerformed(ActionEvent e){
//here I would like to change the imageIcon.
}
};
JMenuItem newOnOffMI = new JMenuItem(actionOnOff);
********************************************************
How can I change the menuItem's icon?
Thanks.
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
check JMenuItem api docco: init(String text, Icon icon)
Initializes the menu item with the specified text and icon.
You may need to run that code in a method in your main class, called by your action listener, because you may not be able to get at the JMenuItem handle within the handler code.


The nice thing about Standards is that there are so many to choose from!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to change the icon of an menuitem's action
 
Similar Threads
Icons
tray icon is not displaying
Custom Icons in JTree
AbstractAction and Mnemonics
a JMenuItem question,the value is too long