JTextPane prevents scrolling in the parent JScrollPane

前端 未结 4 483
温柔的废话
温柔的废话 2021-01-06 00:49

I have the following \"tree\" of objects:

JPanel
    JScrollPane
        JPanel
            JPanel
                JScrollPane
                    JTextPane
         


        
4条回答
  •  醉梦人生
    2021-01-06 01:26

    @Nemi has a good solution already.

    I boiled it down a bit further, putting the follwing method in my library:

    static public void passMouseWheelEventsToParent(final Component pComponent, final Component pParent) {
            pComponent.addMouseWheelListener((final MouseWheelEvent pE) -> {
                pParent.dispatchEvent(new MouseWheelEvent(pParent, pE.getID(), pE.getWhen(), pE.getModifiers(), 1, 1, pE.getClickCount(), false, pE.getScrollType(), pE.getScrollAmount(), pE.getWheelRotation()));
            });
    }
    

提交回复
热议问题