Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Component;
import java.awt.Container;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JScrollPane;

public class Main {
    static Map<String, Component> getComponents(Container container) {

        Map<String, Component> listComponent = Collections.EMPTY_MAP;

        if (container.getComponentCount() > 0) {
            listComponent = new HashMap<>();

            for (Component component : container.getComponents()) {
                if (component.getName() != null) {
                    if (component instanceof JScrollPane) {
                        listComponent.putAll(getComponents(((JScrollPane) component).getViewport()));
                    } else {
                        listComponent.put(component.getName(), component);
                    }
                }
            }

        }

        return listComponent;
    }
}