How do I see if a button with an imageIcon loaded has been pressed in java? -


i have program have settings button. button has image icon shows image. tips on how can preform action when pressed. here code

jbutton imagebutton = new jbutton(new imageicon("/users/sam/programming/files/gears.png")); 

it works fine. when want use

else if(ae.getactioncommand().equals(imagebutton)){//dostuff} 

it doesnt work. action preformed method works, here is

public void actionperformed(actionevent ae) {} 

your actionlisterner not responding because getactioncommand() should return string. in case should name of jbutton.

 else if(ae.getactioncommand().equals(imagebutton.gettext())){//dostuff} 

changing imagebutton.gettext() should solve problem.

if not sure, manually set actioncommand through setactioncommand() , use same string verify getactioncommand in .equals() method.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -