Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.awt.BorderLayout;
import java.awt.Component;

import javax.swing.JComponent;

public class Main {
    public static void showAsOnlyVisibleChild(JComponent container, Component childToBeMadeVisible) {
        for (Component child : container.getComponents()) {
            boolean visible = child.equals(childToBeMadeVisible);
            child.setVisible(visible);
            if (visible) {
                container.getLayout().addLayoutComponent(BorderLayout.CENTER, child);
            } else {
                container.getLayout().removeLayoutComponent(child);
            }
            child.repaint();
        }
        container.revalidate();
        container.repaint();
    }
}