by Dinesh Thakur

Overlay is a process of laying one component over another one. You can use Graphics2d to over layout one textfield component to another textfield.

import java.awt.*;
import javax.swing.*;
public class JavaExampleOverLayInJApplet extends JApplet
{
    public void init()
    {
        Container Cntnr = getContentPane();
        JPanel Pnl = new JPanel();
        Pnl.setLayout(new OverlayLayout(Pnl));
        Pnl.setBackground(Color.white);
        Pnl.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"OverLays"));
        JTextField Txt1 = new JTextField("Text One");
        JTextField Txt2 = new JTextField("Text Two");
        Txt1.setMinimumSize(new Dimension(35,35));
        Txt2.setMinimumSize(new Dimension(35,35));
        Txt1.setPreferredSize(new Dimension(110,110));
        Txt2.setPreferredSize(new Dimension(110,110));
        Txt1.setMaximumSize(new Dimension(125,125));
        Txt2.setMaximumSize(new Dimension(125,125));
        Txt1.setAlignmentX(0.3f);
        Txt1.setAlignmentY(0.3f);
        Txt2.setAlignmentX(0.9f);
        Txt2.setAlignmentY(0.9f);
        Pnl.add(Txt1);
        Pnl.add(Txt2);
        Cntnr.setLayout(new FlowLayout());
        Cntnr.add(Pnl);
    }
}
/*<APPLET  CODE =JavaExampleOverLayInJApplet.class WIDTH = 210  HEIGHT = 210 ></APPLET>*/

OverLay in Java Example