【问题标题】:Get the mouse coordinates inside an JScrollPane获取 JScrollPane 内的鼠标坐标
【发布时间】:2017-06-22 16:19:37
【问题描述】:

谁能告诉我当我在 JScrollPane 内单击时如何获取鼠标坐标?我需要X和Y坐标,可以吗?

【问题讨论】:

  • 当它点击时你需要它,或者当它悬停在窗格周围时你需要它?

标签: java mouse jscrollpane coordinate


【解决方案1】:

附上示例代码

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();

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 2015-11-03
    • 2011-04-11
    相关资源
    最近更新 更多