首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ScrolledComposite不按鼠标滚动

ScrolledComposite不按鼠标滚动
EN

Stack Overflow用户
提问于 2014-09-05 12:05:46
回答 1查看 1.1K关注 0票数 0

鼠标轮在macosx上正常工作,但在windows上不工作。

这里是我的布局结构,我实现了鼠标轮侦听器,但它不触发。

代码语言:javascript
运行
复制
    scrolledComposite.addListener(SWT.MouseWheel, new Listener() {
        public void handleEvent(Event event) {
            System.out.println("MOUSE WHEEL");
            int wheelCount = event.count;
            wheelCount = (int) Math.ceil(wheelCount / 3.0f);
            while (wheelCount < 0) {
                scrolledComposite.getVerticalBar().setIncrement(4);
                wheelCount++;
            }

            while (wheelCount > 0) {
                scrolledComposite.getVerticalBar().setIncrement(-4);
                wheelCount--;
            }
        }
    });

还有我的综合声明:

代码语言:javascript
运行
复制
    final ScrolledComposite scrolledComposite = new ScrolledComposite(mainComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_MAGENTA));

    final Composite listComposite = new Composite(scrolledComposite, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    listComposite.setLayout(layout);

    final Composite composite_3 = new Composite(listComposite, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 8;
    composite_3.setLayout(gridLayout);

    scrolledComposite.setContent(listComposite);
    scrolledComposite.setMinSize(listComposite.computeSize(SWT.DEFAULT,SWT.DEFAULT));

/示例从零开始,也不起作用。

代码语言:javascript
运行
复制
    shell = new Shell();
    shell.setSize(450, 300);
    shell.setText("SWT Application");
    shell.setLayout(new FormLayout());

    Composite composite = new Composite(shell, SWT.NONE);
    composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
    FormData fd_composite = new FormData();
    fd_composite.bottom = new FormAttachment(0, 46);
    fd_composite.right = new FormAttachment(100);
    fd_composite.top = new FormAttachment(0);
    fd_composite.left = new FormAttachment(0);
    composite.setLayoutData(fd_composite);
    composite.setLayout(new FillLayout(SWT.HORIZONTAL));

    Composite composite_1 = new Composite(shell, SWT.NONE);
    FormData fd_composite_1 = new FormData();
    fd_composite_1.right = new FormAttachment(0, 100);
    fd_composite_1.top = new FormAttachment(composite, 1);
    fd_composite_1.left = new FormAttachment(0);
    fd_composite_1.bottom = new FormAttachment(100);
    composite_1.setLayoutData(fd_composite_1);

    Composite composite_2 = new Composite(shell, SWT.NONE);
    composite_2.setLayout(new FillLayout(SWT.HORIZONTAL));
    FormData fd_composite_2 = new FormData();
    fd_composite_2.top = new FormAttachment(composite, 1);
    fd_composite_2.left = new FormAttachment(composite_1, 1);
    fd_composite_2.bottom = new FormAttachment(100);
    fd_composite_2.right = new FormAttachment(100);
    composite_2.setLayoutData(fd_composite_2);

    ScrolledComposite scrolledComposite = new ScrolledComposite(composite_2, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);

    Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
    composite_3.setLayout(new GridLayout(1, false));

    Composite composite_4 = new Composite(composite_3, SWT.NONE);
    composite_4.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLUE));

    Composite composite_5 = new Composite(composite_3, SWT.NONE);
    composite_5.setBackground(SWTResourceManager.getColor(SWT.COLOR_MAGENTA));

    Composite composite_7 = new Composite(composite_3, SWT.NONE);
    composite_7.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_BLUE));

    Composite composite_6 = new Composite(composite_3, SWT.NONE);
    scrolledComposite.setContent(composite_3);
    scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
EN

回答 1

Stack Overflow用户

发布于 2015-02-05 11:48:32

我也遇到了同样的问题,在谷歌搜索后,我发现了这个问题:

代码语言:javascript
运行
复制
scrolledComposite.addListener(SWT.Activate, new Listener() {
        public void handleEvent(Event e) {
            scrolledComposite.setFocus();
        }
    });

对我起作用了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25685522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档