Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ScrollingImagePanel + MouseListener

Status
Not open for further replies.

pinkipons

Programmer
Mar 19, 2002
4
MX
Hello!

I´m working with images. My program displays an image in a ScrollingImagePanel, I want to click the image and get the x,y coordinates. I try to do this adding a Mouse listener but I didn´t obtain good results. If I add the same listener to another component it works fine. What am I doing wrong? Here is part of my code:

panel1i=new ScrollingImagePanel(imagen,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

panel1i.addMouseListener( new MouseClickHandler() );
panel0.add(BotonEntrena);
panel2.add(panel1i);
c.add(panel2,BorderLayout.CENTER);

// inner class to handle mouse events
private class MouseClickHandler extends MouseAdapter {
public void mouseClicked( MouseEvent e )
{
xPos = e.getX();
yPos = e.getY();
String s =
"x = " + xPos + " y = " + yPos;

System.out.println("x = " + xPos + " y = " + yPos);
setTitle( s ); // set the title bar of the window
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top