Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Component;

import javax.swing.JComponent;
import javax.swing.JScrollPane;

public class Main {
    /**
     * Gets the scroll pane around the component.
     *
     * @param innerComponent
     * @return the scroll pane. Null if the component is not in any JScrollPane.
     */
    public static Component getScrollPane(Component innerComponent) {
        Component component = innerComponent;

        if ((component.getParent() != null) && (component.getParent().getParent() != null)
                && (component.getParent().getParent() instanceof JScrollPane)) {
            component = (JComponent) component.getParent().getParent();

            return component;

        } else {
            return null;
        }
    }
}