You are here:   HomeJava ProgrammingSwingOverLay in Java Example
by Dinesh Thakur Category: Swing

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





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article