Linux上的SWT滚动条事件 [英] SWT Scrollbar events on Linux

查看:136
本文介绍了Linux上的SWT滚动条事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照此处的要求滚动画布的一部分我无法收听滚动条上的鼠标事件.经过调查,我发现这是由于GTK中的错误所致.在这里看到 https://bugs.eclipse.org/bugs/show_bug.cgi? id = 51995 .现在已修复,但我不知道如何在计算机上解决它(Ubuntu 12.04).在这方面可以帮助我吗?

As asked here Scrolling part of the canvas I am not able to listen the mouse events on scrollbars. After investigation I found that it is due to a bug in GTK. See here https://bugs.eclipse.org/bugs/show_bug.cgi?id=51995. It is fixed now but I don’t know how to resolve it on my machine(Ubuntu 12.04). Can any body help me in this regard?

推荐答案

您可以如下所述在滚动条或滑块上检测鼠标事件.

You can detect the mouse events on scrollbar or slider as mentioned below.

将页面增量和增量值设置为滑块"或滚动条".

Set the page increment and increment values to Slider or Scrollbar.

sbr.setPageIncrement(100);//滚动条将前后移动100个像素 单击拇指和左箭头按钮之间的区域或之间的区域时 拇指和向右箭头按钮.

sbr.setPageIncrement(100); //Scrollbar will be moved 100 pixel back or forth when clicked on area between thumb and left arrow button or area between thumb and right arrow button.

sbr.setIncrement(10);//滚动条将在以下情况下前后移动10个像素 点击了向左或向右箭头按钮.

sbr.setIncrement(10); //Scrollbar will be moved 10 pixel back or forth when clicked on left or right arrow button.

在滚动条或滑块选择侦听器中添加以下代码

Add the below code in scrollbar or slider selection listener

sbr.addListener(SWT.Selection, new Listener() {
  @Override
  public void handleEvent(Event event) {
      int hSelection = sbr.getSelection();

      if (hSelection - prevHselection == sbr.getIncrement()) {
         System.out.println("clicked right arrow button");
      } else if (hSelection - prevHselection == -sbr.getIncrement()) {
         System.out.println("clicked left arrow button");
      } else if (hSelection - prevHselection == sbr.getPageIncrement()) {
         System.out.println("clicked on area between thumb and right arrow button");              
      } else if (hSelection - prevHselection == -sbr.getPageIncrement()) 
         System.out.println("clicked on area between thumb and left arrow button");   
      } else if(hSelection - prevHselection > 0){
         System.out.println("Thumb is dragged forward");                 
      } else if(hSelection - prevHselection < 0){
         System.out.println("Thumb is dragged backward");                 
      }

      prevHselection = hSelection; //create field prevSelection
  }
}

请注意,在客户端调整大小之后,更新页面增量和增量值.

Note AFTER client resize update page increment and increment values.

这篇关于Linux上的SWT滚动条事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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