Slide 1
Slide 2
Slide 3

Mouse Wheel Event in java programming (V72)

No Comments

MouseWheelEvent
MouseWheelEvent is an event that occurs when the mouse wheel is moved (scrolled) by the user. It is used to detect scrolling upward or downward.
Example: 


Source Code:

Copied!
    private void jpanelwheelMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {                                            
                                       
        int notches = evt.getWheelRotation();

        if (notches < 0) {
            labelshow.setText("Mouse wheel moved UP");
            fontSize += 2;
        } else {
            labelshow.setText("Mouse wheel moved DOWN");
            fontSize = Math.max(8, fontSize - 2); // Minimum font size = 8
        }

        labelshow.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, fontSize));

    }                                                 

Result:


Watch the video:


Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

back to top