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:
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

