Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import javax.swing.JScrollPane;
import javax.swing.JScrollBar;
import javax.swing.SwingUtilities;

public class Main {
    /**
     * Scrolls scroll pane to the top left corner a bit later.
     * @see #scrollToTop(JScrollPane)
     */
    public static void scrollToTopLater(final JScrollPane scrollPane) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                scrollToTop(scrollPane);
            }
        });
    }

    /**
     * Scrolls scroll pane to the top left corner.
     */
    public static void scrollToTop(final JScrollPane scrollPane) {
        JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
        JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar();
        verticalScrollBar.setValue(verticalScrollBar.getMinimum());
        horizontalScrollBar.setValue(horizontalScrollBar.getMinimum());
    }
}