Creating and Setting a Border - Java Swing

Java examples for Swing:Border

Description

Creating and Setting a Border

Demo Code

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;

public class Main {
  public static void main(String[] argv) {
 // Create a border
    EmptyBorder emptyBorder = (EmptyBorder)BorderFactory.createEmptyBorder();

    LineBorder lineBorder = (LineBorder)BorderFactory.createLineBorder(Color.black);

    EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder();

    BevelBorder raisedBevelBorder = (BevelBorder)BorderFactory.createRaisedBevelBorder();

    BevelBorder loweredBevelBorder = (BevelBorder)BorderFactory.createLoweredBevelBorder();

    ImageIcon icon = new ImageIcon("image.gif");
    MatteBorder matteBorder = (MatteBorder)BorderFactory.createMatteBorder(-1, -1, -1, -1, icon);


    // Set the border
    new JButton().setBorder(emptyBorder);
  }//  ww w  . j a  v a 2s  .c o  m

}

Related Tutorials