CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Swing > EtchedBorder in Java Swing

Swing Tutorial

  • What Is Java Swing
  • First Program
  • What is AWT
  • Advantages of Swing Over AWT
  • JFrame
  • Swing Components
  • JLabel
  • JTextField
  • JPasswordField
  • JButton
  • Event Handling
  • FlowLayout
  • BorderLayout
  • GridLayout
  • GridBagLayout
  • BoxLayout
  • JPanel
  • JCheckBox
  • JRadioButton
  • Border Component
  • JComboBox
  • JList
  • JList with MVC
  • Mouse Event
  • Key Event
  • JMenuBar
  • JTextArea
  • Using Color
  • Use Font
  • Display Image/Icon
  • Dialog Box
  • JTable
  • JDesktopPane and JInternalFrame
  • JDesktopPane
  • JInternalFrame
  • Adapter Classes
  • Swing Timer
  • JScrollPane
  • JSlider
  • JProgressBar
  • JSeparator
  • JToolBar
  • ActionListener
  • ItemListener
  • Worker Thread
  • Nimbus Look and Feel

EtchedBorder in Java Swing

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 3 min read · 0 Comments
Share: in X

EtchedBorder is a class in the Java Swing library that can be used to create a border with an etched or raised effect. It is a subclass of the AbstractBorder class, which provides a basic implementation for creating borders.

To use EtchedBorder, we first need to create an instance of the class and set any properties we want to customize. For example, we can set the border style to either etched or raised, and we can specify the color of the border.

Following is an example of how to create an EtchedBorder with a raised style and a gray color:

import javax.swing.*;
import javax.swing.border.*;

// create a panel with an etched border
JPanel panel = new JPanel();
Border border = BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.GRAY);
panel.setBorder(border);

In this example, the createEtchedBorder method of the BorderFactory class is used to create a new EtchedBorder instance with a raised style and a gray color. The border object is then set as the border of a JPanel component.

We can also customize the thickness of the border by passing an additional parameter to the createEtchedBorder method:

Border border = BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.YELLOW, Color.GRAY);

In this case, the third parameter specifies the color of the shadow that is used to create the etched effect.

The complete example code is given below;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

public class EtchedBorderDemo extends JFrame {

	public EtchedBorderDemo() {
		setTitle("EtchedBorder Demo");
		// set up the frame
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(400, 400);
		
		setLayout(new BorderLayout());

		// create a panel with an etched border
		JPanel panel = new JPanel();
		Border border = BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.YELLOW, Color.GRAY);
		panel.setBorder(border);

		// add some components to the panel
		JLabel label = new JLabel("Hello, world!");
		panel.add(label);

		JButton button = new JButton("Click me!");
		panel.add(button);

		JTextField textField = new JTextField("Type something...");
		panel.add(textField);

		// add the panel to the frame
		getContentPane().add(panel, BorderLayout.NORTH);

		// display the frame
		setVisible(true);
	}

	public static void main(String[] args) {
		new EtchedBorderDemo();
	}

}

This code creates a new JFrame instance and sets its size and close operation. Then it creates a JPanel with an etched border and adds some Swing components to it (a JLabel, a JButton, and a JTextField). Finally, the panel is added to the frame and the frame is displayed.

Output:

EtchedBorder demo 1

EtchedBorder can be used to create borders for any Swing component that supports borders, including JButton, JLabel, JTextField, and others.

Reference: https://docs.oracle.com/javase/7/docs/api/javax/swing/border/EtchedBorder.html

Related Posts:

  • Most Frequently Asked Spring Boot Interview…
  • Inheritance in Java: A Developer’s Guide to Code Reusability
  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
  • Abstract Class in Java: Bridging Code Reusability…
  • Control Statements in Java
  • MySQL Commands for Developers
Tags:javaswing
Was this article helpful?
← Previous ArticleInner Thread Communication in Java
Next Article →Thread Deadlock in Java

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap