BorderTest.java Source code

Java tutorial

Introduction

Here is the source code for BorderTest.java

Source

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class BorderTest extends JFrame {
    public BorderTest() {
        JPanel p = new JPanel();
        Border[] border = new Border[] { BorderFactory.createEtchedBorder(),
                BorderFactory.createTitledBorder("Border types"), BorderFactory.createLoweredBevelBorder(),
                BorderFactory.createRaisedBevelBorder(), BorderFactory.createEtchedBorder(),
                BorderFactory.createLineBorder(Color.blue),
                BorderFactory.createMatteBorder(10, 10, 10, 10, Color.blue), BorderFactory.createEmptyBorder()

        };
        p.setLayout(new GridLayout(border.length, 0, 3, 3));

        for (int i = 0; i < border.length; i++) {
            JPanel borderPanel = new JPanel();
            borderPanel.setBorder(border[i]);
            p.add(borderPanel);
        }
        getContentPane().add(p, "Center");
        setTitle("BorderTest");
        setSize(600, 400);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

    public static void main(String[] args) {
        JFrame frame = new BorderTest();
        frame.show();
    }

}