java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to turn the Scroll Lock button on?

The program below show you how to turn the scroll lock button on programatically. Setting the locking state to Boolean.TRUE activate the scroll lock.

package com.javacoderanch.example.awt;

import java.awt.*;
import java.awt.event.KeyEvent;

public class TurnScrollLockOn {
    public static void main(String[] args) {
        //
        // Gets the default toolkit.
        //
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        
        //
        // Update the locking state for scroll lock button to true
        // will turn the scroll lock on.
        //
        toolkit.setLockingKeyState(KeyEvent.VK_SCROLL_LOCK, Boolean.TRUE);
    }
}