JScrollPane中的JScrollPane [英] JScrollPane in JScrollPane

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

问题描述

我有一个JScrollPane,其内容窗格中有一个JPanel.在该JPanel中添加较小的JPanel,并且如预期的那样,如果添加过多的JPanel,则会出现一个垂直滚动条.

I have a JScrollPane, which has a JPanel for its content pane. To that JPanel I add smaller JPanels, and as expected, if I add too much JPanel, a vertical scrollbar will appear.

问题是,我的小JPanel对于JEditorPane也包含一个JScrollPane.我只想将鼠标滚轮用于外部滚动窗格,而不用于较小的滚动窗格.我已经将小滚动窗格的wheelScrollingEnabled()设置为false,但是如果我向任意方向滚动,并且鼠标越过JEditorPane,则滚动将不再起作用.

The problem is, that my small JPanels contains a JScrollPane too for a JEditorPane. I'd like to use the mouse wheel only for the outer scrollpane, not for the smaller scrollpane. I already set wheelScrollingEnabled() to false for the small scrollpane, but if I scroll in any direction, and the mouse gets over the JEditorPane, the scrolling doesn't work anymore.

有什么建议吗?

推荐答案

您可以尝试将wheel事件从内部滚动窗格转发到其父级.

You may try to forward the wheel events from the inner scroll pane to its parent.

innerScrollPane.addMouseWheelListener(new MouseWheelListener() {

    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {
        innerScrollPane.getParent().dispatchEvent(e);
    }
});

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

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