zoukankan      html  css  js  c++  java
  • e822. 监听JScrollPane的滚动

    A scrollbar in a scroll pane fires adjustment events whenever its value changes.

        // Create a scrollable text area
        JTextArea textArea = new JTextArea();
        JScrollPane pane = new JScrollPane(textArea);
        
        // Listen for value changes in the scroll pane's scrollbars
        AdjustmentListener listener = new MyAdjustmentListener();
        pane.getHorizontalScrollBar().addAdjustmentListener(listener);
        pane.getVerticalScrollBar().addAdjustmentListener(listener);
        
        class MyAdjustmentListener implements AdjustmentListener {
            // This method is called whenever the value of a scrollbar is changed,
            // either by the user or programmatically.
            public void adjustmentValueChanged(AdjustmentEvent evt) {
                Adjustable source = evt.getAdjustable();
        
                // getValueIsAdjusting() returns true if the user is currently
                // dragging the scrollbar's knob and has not picked a final value
                if (evt.getValueIsAdjusting()) {
                    // The user is dragging the knob
                    return;
                }
        
                // Determine which scrollbar fired the event
                int orient = source.getOrientation();
                if (orient == Adjustable.HORIZONTAL) {
                    // Event from horizontal scrollbar
                } else {
                    // Event from vertical scrollbar
                }
        
                // Determine the type of event
                int type = evt.getAdjustmentType();
                switch (type) {
                  case AdjustmentEvent.UNIT_INCREMENT:
                      // Scrollbar was increased by one unit
                      break;
                  case AdjustmentEvent.UNIT_DECREMENT:
                      // Scrollbar was decreased by one unit
                      break;
                  case AdjustmentEvent.BLOCK_INCREMENT:
                      // Scrollbar was increased by one block
                      break;
                  case AdjustmentEvent.BLOCK_DECREMENT:
                      // Scrollbar was decreased by one block
                      break;
                  case AdjustmentEvent.TRACK:
                      // The knob on the scrollbar was dragged
                      break;
                }
        
                // Get current value
                int value = evt.getValue();
            }
        }
    
    Related Examples
  • 相关阅读:
    推荐一本书 改善你的视力:跟眼镜说再见
    Gentoo中gcc4.1.2到gcc4.3.2的升级
    msbuild学习的一些相关链接
    SqlServer 2005安装问题
    Gentoo linux中安装php5运行环境
    sql 时间函数(全)
    asp.net中的对话框
    win7 资源管理器指向我的电脑
    C/C++ 位操作 总结
    【转】Java字节序转换
  • 原文地址:https://www.cnblogs.com/borter/p/9596216.html
Copyright © 2011-2022 走看看