- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the importance of JSeparator class in Java?
JSeparator
- A JSeparator is a horizontal or vertical line or an empty space that separates the components.
- A JSeparator class is used to draw a line to separate the components in a Layout.
- The easiest way to add a separator to a menu or toolbar is to call the addSeparator() method provided by the classes JMenu, JPopupMenu and JToolBar.
- The important methods of JSeparator class are setOrientation() and getOrientation().
Example
import java.awt.*; import javax.swing.*; public class JSeparatorTest extends JFrame { private JLabel label1, label2; public JSeparatorTest() { setTitle("JSeparator Test"); setLayout(new GridLayout(0, 1)); label1 = new JLabel("Above Separator"); add(label1); JSeparator sep = new JSeparator(); add(sep); // add a separator between two labels. label2 = new JLabel("Below Separator"); add(label2); setSize(375, 250); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public static void main(String args[]) { new JSeparatorTest(); } }
Output
- Related Articles
- What is the importance of SwingUtilities class in Java?
- What is the importance of Runtime class in Java?
- What is the importance of JViewport class in Java?
- What is the importance of the GridBagConstraints class in Java?
- What is the importance of the CardLayout class in Java?
- What is the importance of the Container class in Java?
- What is the importance of Boolean class in Java?\n
- What is the importance of a Cursor class in Java?
- What is the importance of a SwingWorker class in Java?\n
- What is the importance of the Throwable class and its methods in Java?
- Importance of StringReader class in Java?\n
- Importance of a Dictionary class in Java?
- Importance of a Locale class in Java?
- Importance of MethodHandles class in Java 9?
- What is the importance of "Java.lang.Class" in Java?

Advertisements