setBounds with border

//<applet code=SetBoundsDemo height=500 width=500></applet>

import java.awt.Color;
import java.awt.Font;
import javax.swing.*;
import javax.swing.border.Border;

public class SetBoundsDemo extends JApplet {
	JPanel p1;
	JLabel head, l1, l2, l3;
	JTextField t1, t2, t3;
	JButton b1, b2, b3;
	// for border
	Border etchedBdr;

	@Override
	public void init() {
		
		super.init();
		etchedBdr = BorderFactory.createEtchedBorder();

		getContentPane().add(p1 = new JPanel());
		p1.setBackground(new Color(162, 205, 90));
		p1.setLayout(null);
		
		head = new JLabel("Employee Registration Form");
		// head.setBounds(int x,int y,int width,int height);
		head.setBounds(300, 20, 450, 50);
		head.setBackground(Color.yellow);
		head.setForeground(Color.red);
		head.setFont(new Font("Tohama", Font.BOLD, 30));
		head.setBorder(etchedBdr);
		p1.add(head);

		l1 = new JLabel("Enter id");
		l1.setBounds(100, 100, 200, 30);
		l1.setBorder(etchedBdr);
		p1.add(l1);

		t1 = new JTextField(30);
		t1.setBounds(350, 100, 200, 30);
		t1.setBorder(etchedBdr);
		p1.add(t1);

		l2 = new JLabel("Enter Name");
		l2.setBounds(100, 150, 200, 30);
		l2.setBorder(etchedBdr);
		p1.add(l2);

		t2 = new JTextField(30);
		t2.setBounds(350, 150, 200, 30);
		t2.setBorder(etchedBdr);
		p1.add(t2);

		l3 = new JLabel("Enter City");
		l3.setBounds(100, 200, 200, 30);
		l3.setBorder(etchedBdr);
		p1.add(l3);

		t3 = new JTextField(30);
		t3.setBounds(350, 200, 200, 30);
		t3.setBorder(etchedBdr);
		p1.add(t3);

		b1 = new JButton("Save");
		b1.setBounds(110, 250, 90, 30);
		b1.setBorder(etchedBdr);
		p1.add(b1);

		b2 = new JButton("Cancel");
		b2.setBounds(230, 250, 90, 30);
		b2.setBorder(etchedBdr);
		p1.add(b2);

		b3 = new JButton("Reset");
		b3.setBounds(350, 250, 90, 30);
		b3.setBorder(etchedBdr);
		p1.add(b3);
	}

}

Download

Layout Manager in Java

Border Layout
Box Layout
Card Layout
Flow Layout
Gridbag Layout
Gridbag Layout
Grid Layout
Design GUI contianer without layout


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code