在Java Swing中检测JScrollPane上的mouseClick事件 [英] Detecting mouseClick event on JScrollPane in Java Swing

查看:95
本文介绍了在Java Swing中检测JScrollPane上的mouseClick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有类似的内容,可以在其中使用布尔标志"performAdjustment"控制自动滚动:

If i have something like this, where i can control the auto-scrolling using boolean flag "performAdjustment":

static boolean performAdjustment = true;

JTextArea textArea = new JTextArea();
JScrollPane jScrollPane1 = new JScrollPane(textArea);

   jScrollPane1.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {  
            public void adjustmentValueChanged(AdjustmentEvent e) { 
                if(performAdjustment){
                    e.getAdjustable().setValue(e.getAdjustable().getMaximum());  
                }
        }}); 

现在我可以正常工作了,但是问题是我想在用户单击滚动条时取消设置此布尔值标志,并且当用户单击时应再次设置该布尔标志(例如JavaScript中的onMouseOut事件).

Now i this works fine, but the problem is i want to unset this boolean flag when a user clicks on the scroll bar and it should be set again when the user leave the click (like onMouseOut event in JavaScript).

您能告诉我如何添加这个新的EventListener,以检测滚动条的单击事件吗?

Can you tell me how can i add this new EventListener where i can detect click event of the scroll bar??

推荐答案

我很确定鼠标侦听器应该可以帮助您实现所需的目标;

I'm pretty sure a mouse listener should help you to achieve what you want;

jScrollPane1.getVerticalScrollBar().addMouseListener(...)

这篇关于在Java Swing中检测JScrollPane上的mouseClick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆