在JScrollPane

时间:2017-06-22 08:00:16

标签: java mouse jscrollpane coordinate

当有人点击JScrollPane时,有人可以告诉我如何获取鼠标坐标吗?我需要X和Y坐标,这可能吗?

1 个答案:

答案 0 :(得分:0)

这是附加的示例代码

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

public class Solution extends JFrame {
    public void init(){

        this.setSize(600,600);
        JScrollPane pane=new JScrollPane();
        this.add(pane);
        setVisible(true);
        pane.addMouseListener(new MouseAdapter() {



            @Override
            public void mousePressed(MouseEvent e) {
                System.out.println("Mouse X="+e.getY()+" Mouse Y="+e.getY());

            }

        });
    }
    public static void main(String[] args) {
        new Solution().init();

    }
}