Borders in Swing

import java.awt.Color;
import java.awt.Font;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.TitledBorder;

public class BorderDemo2 extends JApplet {
	JPanel p1;
	JButton b[];

	@Override
	public void init() {
		getContentPane().add(p1 = new JPanel());
		b = new JButton[15];
		for (int i = 0; i < b.length; i++) {
			b[i] = new JButton("Button " + i);
			b[i].setFont(new Font("Arial", Font.BOLD, 15));
		}

		// empty border
		b[0].setText("Empty Border");
		b[0].setBorder(new EmptyBorder(1, 2, 3, 4));
		p1.add(b[0]);

		// empty border
		b[1].setText("BevelBorder");
		b[1].setBorder(new BevelBorder(5));
		p1.add(b[1]);

		// empty border
		b[2].setText("CompoundBorder");
		b[2].setBorder(new CompoundBorder(b[0].getBorder(), new EtchedBorder()));
		p1.add(b[2]);

		// EtchedBorder border
		b[3].setText("EtchedBorder");
		b[3].setBorder(new EtchedBorder());
		p1.add(b[3]);

		// LineBorder border
		b[4].setText("LineBorder");
		b[4].setBorder(new LineBorder(Color.red));
		p1.add(b[4]);

		// MatteBorder border
		b[5].setText("MatteBorder");
		b[5].setBorder(new MatteBorder(2, 2, 2, 2, Color.blue));
		p1.add(b[5]);

		// SoftBevelBorder border
		b[6].setText("SoftBevelBorder");
		b[6].setBorder(new SoftBevelBorder(2));
		p1.add(b[6]);

		// TitledBorder border
		b[7].setText("TitledBorder");
		TitledBorder tb = new TitledBorder("title border");
		tb.setTitleColor(Color.blue);
		b[7].setBorder(tb);
		p1.add(b[7]);
	}
}

Download

Borders in Java

Border factory Example - LineBorder,BevelBorder,TitledBorder,EtchedBorder etc
Border in Swing  
Custom Border


Write your Comment

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