This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to change the icon of an menuitem's action  RSS feed

 
Edu Cobi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!