CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Swing > Border Component 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

Border Component 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 ยท 1 min read ยท 0 Comments
Share: in X

In Java Swing, a border is a component that can be added to a container or a component to provide a visual decoration or separation between the container and its contents. There are several types of borders available in Swing, including:

  1. LineBorder: Draws a single line around the component with a specified color and thickness.
  2. EtchedBorder: Draws a raised or lowered etched line around the component, depending on the type of border specified.
  3. BevelBorder: Draws a beveled edge around the component with either a raised or lowered appearance.
  4. TitledBorder: Draws a border around the component with a specified title.
  5. CompoundBorder: Allows us to combine two or more borders into a single border.

To add a border to a component, we can use the setBorder() method, which takes a Border object as an argument. For example, to add a line border with a red color and a thickness of 2 pixels to a JButton object, we can use the following code:

JButton button = new JButton("Click me");
button.setBorder(BorderFactory.createLineBorder(Color.RED, 2));

We can also create custom borders by extending the Border class and implementing its methods. This allows us to create borders with custom shapes or behaviors.

Reference: https://docs.oracle.com/javase/tutorial/uiswing/components/border.html

Related Posts:

  • EtchedBorder in Java Swing
  • BevelBorder in Java Swing
  • CompoundBorder in Java Swing
  • LineBorder in Java Swing
  • TitledBorder in Java Swing
  • Using Color in Java Swing
Tags:javaswing
Was this article helpful?
โ† Previous ArticleThread Priority in Java
Next Article โ†’Scrollable ResultSet in JDBC

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