Here you can find the source of autoFitResize(final JLayeredPane pane, final Component... comps)
public static void autoFitResize(final JLayeredPane pane, final Component... comps)
//package com.java2s; //License from project: LGPL import java.awt.Component; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import javax.swing.JLayeredPane; public class Main { public static void autoFitResize(final JLayeredPane pane, final Component... comps) { pane.addComponentListener(new ComponentAdapter() { @Override// ww w. j a va2s .c om public void componentResized(ComponentEvent e) { for (Component comp : comps) { comp.setBounds(0, 0, pane.getWidth(), pane.getHeight()); } pane.revalidate(); pane.repaint(); } }); } }