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

JSeparator 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: August 27, 2021 · 1 min read · 0 Comments
Share: in X

A JSeparator in Java Swing is a graphical component used to visually separate different sections of a user interface. It’s often employed to enhance the organization and readability of GUIs.

Following is a basic example demonstrating the usage of JSeparator:

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

public class JSeparatorDemo extends JFrame {
	public JSeparatorDemo() {
		setTitle("JSeparator Demo");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(new FlowLayout());

		JLabel label1 = new JLabel("Section 1");
		add(label1);

		JSeparator separator1 = new JSeparator();
		separator1.setPreferredSize(new Dimension(200, 10));
		add(separator1);

		JLabel label2 = new JLabel("Section 2");
		add(label2);

		JSeparator separator2 = new JSeparator(SwingConstants.VERTICAL);
		separator2.setPreferredSize(new Dimension(10, 100));
		add(separator2);

		JLabel label3 = new JLabel("Section 3");
		add(label3);

		pack();
		setLocationRelativeTo(null); // Center the window
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(() -> {
			new JSeparatorDemo().setVisible(true);
		});
	}

}

Output:

JSeparator Demo in java swing

Related Posts:

  • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
  • MySQL Commands for Developers
  • Control Statements in Java
  • Interface in Java: Mastering Abstraction and…
  • JCheckBox in Java Swing
  • Java Swing Tutorial
Tags:guijavaswing
Was this article helpful?
← Previous ArticleJProgressBar in Java Swing
Next Article →JMenuBar in Java Swing

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.

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