package test; import javax.swing.*; import java.awt.*; /** * OverlayLayoutTest * * @author Eugene Matyushkin */ public class OverlayLayoutTest extends JFrame{ public OverlayLayoutTest(){ super("OverlayLayout"); JPanel content = new JPanel(); content.setLayout(new OverlayLayout(content)); JLabel lbl = new JLabel("Label 1"); lbl.setFont(lbl.getFont().deriveFont(30f)); lbl.setForeground(Color.blue); content.add(lbl); lbl = new JLabel("Label 2"); lbl.setFont(lbl.getFont().deriveFont(40f)); lbl.setForeground(Color.red); content.add(lbl); lbl = new JLabel("Label 3"); lbl.setFont(lbl.getFont().deriveFont(50f)); lbl.setForeground(Color.black); content.add(lbl); getContentPane().add(content, BorderLayout.CENTER); setSize(410,220); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args){ JFrame.setDefaultLookAndFeelDecorated(true); new OverlayLayoutTest().setVisible(true); } }