如何使用我的水平滚轮滚屏触控板,在Java AWT的ScrollPane [英] How to use my trackpad for horizontal mousewheel scrolling in a Java AWT ScrollPane

查看:330
本文介绍了如何使用我的水平滚轮滚屏触控板,在Java AWT的ScrollPane的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像许多现代鼠标和触控板,我的笔记本电脑支持垂直和水平滚动。这是一个令人上瘾的功能,一旦你习惯了它。我只是希望我的Java应用程序通过触控板/鼠标滚轮支持横向滚动,却处处搜索我看来这是不可能在Java中。

我真的希望有人告诉我,我不知怎么做错了,这个功能已经要求行为:的 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6440198

由于无法做到这一点简单的事情其实是我工作的应用程序一个大忌。事实上,对于任何应用程序,我可以想像!我已经投入了一点在Java后端的时间,所以我真的很想找到这个看似简单的事情的解决方案。

问题是,我还能有什么来实现这一行为?甚至在Java暴露在我的原始操作系统级别的事件,我会那么需要从头写这个?

 进口java.awt中的*。公共类ScrollExample扩展画布{    公共无效漆(图形G){        g.setColor(Color.green);
        g.fillOval(0,0,400,400);    }    公共静态无效的主要(字串[] args){        ScrollExample B =新ScrollExample();
        架F =新的帧(滚动示例);        滚动窗格滚动=新的滚动面板(ScrollPane.SCROLLBARS_ALWAYS);
        scroller.add(二,中心);
        f.set preferredSize(新尺寸(500,500));
        f.add(中心,滚动条);
        f.pack();
        f.show();    }}

摇摆例子使用水平和垂直滚动

 进口java.awt中的*。
进口的javax.swing *。公共类ScrollExample继承JPanel {    公共无效漆(图形G){        super.paint(G);        g.setColor(Color.green);
        g.fillOval(0,0,400,400);    }    公共静态无效的主要(字串[] args){        JFrame的F =新的JFrame(滚动示例);
        ScrollExample P =新ScrollExample();
        P.SET preferredSize(新尺寸(1000,1000));        JScrollPane的滚动=新JScrollPane的(P,JScrollPane.VERTICAL_SCROLLBAR_​​ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_​​ALWAYS);
        scroller.getHorizo​​ntalScrollBar()setUnitIncrement(10)。
        scroller.getVerticalScrollBar()setUnitIncrement(10)。        f.set preferredSize(新尺寸(500,500));
        f.add(滚轮,BorderLayout.CENTER);
        f.pack();
        f.show();
    }
}


解决方案

这是默认在Swing虽然垂直scolling支持优先于当两个滚动条是可见的水平滚动。

我希望新的发展,在Swing不是AWT来完成。

编辑:

您应该能够使用鼠标滚轮控制器定制滚动速度。我从来没有尝试过的横向滚动,让我知道如果它的工作原理。

Like many modern mice and trackpads, my laptop supports vertical and horizontal scrolling. It's an addictive feature once you get used to it. I simply want my Java apps to support horizontal scrolling via the trackpad/mousewheel, but everywhere I search it seems that this is not possible in Java.

I really want someone to tell me that I'm somehow doing it wrong, this feature is already requested behaviour: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6440198

The inability to do this simple thing is actually a deal breaker for the app I'm working on. In fact, for any app I can envision! I've invested a bit of time in the Java backend, so I'd really like to find a solution for this seemingly simple thing.

Question is what could I do to implement this behaviour? Are raw OS level events even exposed to me by java, would I then need to write this from scratch?

import java.awt.*;

public class ScrollExample extends Canvas {

    public void paint(Graphics g) {

        g.setColor(Color.green);
        g.fillOval(0,0,400, 400);

    }

    public static void main(String[] args) {

        ScrollExample b = new ScrollExample();
        Frame f = new Frame ("Scroll Example");

        ScrollPane scroller = new ScrollPane (ScrollPane.SCROLLBARS_ALWAYS);
        scroller.add(b,"Center");
        f.setPreferredSize(new Dimension(500,500));
        f.add ("Center",scroller);
        f.pack();
        f.show();

    }

}

Swing example works with both horizontal and vertical scrolling

import java.awt.*;
import javax.swing.*;

public class ScrollExample extends JPanel { 

    public void paint(Graphics g) {

        super.paint(g);

        g.setColor(Color.green);
        g.fillOval(0,0,400, 400);

    }

    public static void main(String[] args) {

        JFrame f = new JFrame ("Scroll Example");
        ScrollExample p = new ScrollExample();
        p.setPreferredSize(new Dimension(1000, 1000));

        JScrollPane scroller = new JScrollPane(p,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scroller.getHorizontalScrollBar().setUnitIncrement(10);
        scroller.getVerticalScrollBar().setUnitIncrement(10);

        f.setPreferredSize(new Dimension(500,500));
        f.add (scroller,BorderLayout.CENTER);
        f.pack();
        f.show();
    }
}

解决方案

This is supported by default in Swing although vertical scolling has priority over horizontal scrolling when both scrollbars are visible.

I would expect new development to be done in Swing not AWT.

Edit:

You should be able to use the Mouse Wheel Controller to customize the scroll speed. I've never tried it on horizontal scrolling, let me know if it works.

这篇关于如何使用我的水平滚轮滚屏触控板,在Java AWT的ScrollPane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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