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 -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -