Java BorderFactory create various borders

Description

Java BorderFactory create various borders

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.FlowLayout;

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

public class Main extends JFrame {

   public Main() {
      this.setTitle("Example");
      this.setBounds(100, 100, 200, 100);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      this.add(createPanel(BorderFactory.createRaisedSoftBevelBorder()));

      this.add(createPanel(BorderFactory.createRaisedSoftBevelBorder()));
      this.add(createPanel(BorderFactory.createLineBorder(Color.BLACK, 1, true)));
      this.add(createPanel(BorderFactory.createLoweredSoftBevelBorder()));
      this.add(createPanel(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED)));
      this.add(createPanel(BorderFactory.createSoftBevelBorder(BevelBorder.RAISED)));
      this.add(createPanel(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, Color.lightGray, Color.yellow)));
      this.add(createPanel(BorderFactory.createSoftBevelBorder(BevelBorder.RAISED, Color.lightGray, Color.yellow)));
      this.add(createPanel(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, Color.lightGray, Color.lightGray,
            Color.white, Color.orange)));
      this.add(createPanel(BorderFactory.createStrokeBorder(new BasicStroke(1.0f))));// BasicStroke.CAP_SQUARE,BasicStroke.JOIN_BEVEL)));
      this.add(createPanel(BorderFactory.createDashedBorder(Color.red)));
      this.add(createPanel(BorderFactory.createDashedBorder(Color.red, 4.0f, 1.0f)));
      this.add(createPanel(BorderFactory.createDashedBorder(Color.red, 2.0f, 10.0f, 1.0f, true)));

      this.setLayout(new FlowLayout());
   }/*  w ww.j a  va  2s .c  o  m*/

   private JPanel createPanel(Border border) {
      JPanel panel = new JPanel(new FlowLayout());
      panel.setBorder(border);
      return panel;
   }

   public static void main(String[] args) {
      Main window = new Main();
      window.setVisible(true);
   }
}



PreviousNext

Related