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

MatteBorder in Java Swing

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

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Published: March 22, 2021 · 2 min read · 0 Comments
Share: X in 🔗

In Java Swing, the MatteBorder class is used to create a border with a solid color that has a matte-like finish. It is a subclass of the javax.swing.border.Border class and is included in the javax.swing.border package.

To use the MatteBorder class, we first need to create an instance of it by specifying the border width, insets, and color. The border width is the thickness of the border in pixels, the insets define the distance between the border and the component’s edge, and the color specifies the color of the border.

Following is an example of how to create a MatteBorder with a width of 5 pixels to all the corner except left corner, and a red color:

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.MatteBorder;

public class MatteBorderDemo extends JFrame {

	public MatteBorderDemo() {
		JPanel panel = new JPanel();
		MatteBorder border = new MatteBorder(5, 1, 5, 5, Color.RED);// top, left, bottom, right and color
		panel.setBorder(border);
		add(panel);

		setTitle("MatteBorder Demo");
		setSize(300, 300);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		setVisible(true);
	}

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

}

In this example, we create a JPanel and set its border to a MatteBorder with the specified properties. We then add the panel to the JFrame and set the frame properties. When we run the program, we see a red border around the panel with a matte-like finish.

Output:

MatteBorder demo

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

Related Posts:

  • Packages in Java: A Guide to Modular, Maintainable Code
  • Access Modifiers in Java
  • Inheritance in Java: A Developer’s Guide to Code Reusability
  • Abstract Class in Java: Bridging Code Reusability…
  • Most Frequently Asked Spring Boot Interview…
  • Control Statements in Java
Tags:javaswing
Was this article helpful?
← Previous ArticleTitledBorder in Java Swing
Next Article →java.lang Package

Recent Posts

  • 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
  • Complete Guide to JaCoCo: How to Measure Java Code Coverage Accurately
CoderSathi

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

Quick Links

  • About
  • Contact

Popular Topics

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