Java JSeparator() Constructor

Syntax

JSeparator() constructor from JSeparator has the following syntax.

public JSeparator()

Example

In the following code shows how to use JSeparator.JSeparator() constructor.


import java.awt.GridLayout;
//from  w w w .  j  a  va 2  s. c  om
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSeparator;

public class Main {
  public static void main(String args[]) {
    JFrame f = new JFrame("JSeparator Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLayout(new GridLayout(0, 1));
    JLabel above = new JLabel("Above Separator");
    f.add(above);
    JSeparator separator = new JSeparator();
    f.add(separator);
    JLabel below = new JLabel("Below Separator");
    f.add(below);
    f.setSize(300, 100);
    f.setVisible(true);
  }
}