dins88
dins88

Reputation: 185

How disable mouse wheel scroll on all component except parent

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

Upvotes: 0

Views: 272

Answers (2)

68060
68060

Reputation: 427

I did this in my panel and it worked...

 jScrollPane1.removeMouseWheelListener(jScrollPane1.getMouseWheelListeners()[0]);

Upvotes: 1

dins88
dins88

Reputation: 185

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); 

Upvotes: 1

Related Questions