swing - Add MouseListener to java.awt.Image -
is there way can add mouselistener image? took @ this stackoverflow question, didn't answer how java.awt.image
, there no graphics2d image class. or @ least 1 i've found.
edit:
to clarify, let me try explain:
with ellipse2d
, can say:
if(ellipse2d.contains(mousex, mousey) { ...do }
is possible java.awt.image
(i.e. image.contains()
)
also, how image gets added jpanel:
image image = item.geticon().getimage(); //item.geticon() returns javax.swing.imageicon g.drawimage(image, imagex, imagey, null);
you can put image in jlabel , add listener jlabel
imageicon image = item.geticon(); jlabel labelwithimage = new jlabel(image); labelwithimage.addmouselistener(new mouseadapter() { @override public void mouseentered(mouseevent e) { system.out.println("mouse entered on image"); } }); panel.add(labelwithimage);
Comments
Post a Comment