Here you can find the source of showAsOnlyVisibleChild(JComponent container, Component childToBeMadeVisible)
public static void showAsOnlyVisibleChild(JComponent container, Component childToBeMadeVisible)
//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);/*from w w w .ja va 2 s. c om*/ if (visible) { container.getLayout().addLayoutComponent(BorderLayout.CENTER, child); } else { container.getLayout().removeLayoutComponent(child); } child.repaint(); } container.revalidate(); container.repaint(); } }