Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a jFrame along with jScrollPane in this jScrollPane there are few other component such as jTextField jTextArea jTable etc.. (this form I have designed with NetBeans form designer)

jScrollPane (the Parent Component) has vertical scroll bar and it scroll with the mouse wheel. But when mouse move on a jTextArea or a jTable (they have there own scroll bars) Mouse Wheel focus goes to them and scrolling them instead of scrolling jScrollPane. I want to keep scroll focus on jScrollPane without going it to any other component in it. enter image description here

question from:https://stackoverflow.com/questions/66062208/how-disable-mouse-wheel-scroll-on-all-component-except-parent

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
331 views
Welcome To Ask or Share your Answers For Others

1 Answer

found a solution

scrollPane = new JScrollPane() {

    @Override
    protected void processMouseWheelEvent(MouseWheelEvent e) {
        if (!isWheelScrollingEnabled()) {
            if (getParent() != null) 
                getParent().dispatchEvent(
                        SwingUtilities.convertMouseEvent(this, e, getParent()));
            return;
        }
        super.processMouseWheelEvent(e);
    }

};
scrollPane.setWheelScrollingEnabled(false); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...