create Separator for JPanel - Java Swing

Java examples for Swing:JPanel

Description

create Separator for JPanel

Demo Code


//package com.java2s;
import java.awt.Dimension;

import javax.swing.JPanel;

import javax.swing.border.EtchedBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.JPanel;

public class Main {
    public static void main(String[] argv) throws Exception {
        int width = 2;
        System.out.println(createSeparator(width));
    }//  w  w  w .  j a v  a  2s .c om

    private static JPanel createSeparator(int width) {
        //
        // Create a line seperator
        //

        JPanel line = new JPanel();
        line.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
        line.setPreferredSize(new Dimension(width, 2));
        JPanel lineHolder = new JPanel();
        lineHolder.add(line);
        lineHolder.setBorder(new EmptyBorder(3, 10, 3, 10));
        return line;
    }
}

Related Tutorials