Java Swing Tutorial - Java BorderFactory .createCompoundBorder ()








Syntax

BorderFactory.createCompoundBorder() has the following syntax.

public static CompoundBorder createCompoundBorder()

Example

In the following code shows how to use BorderFactory.createCompoundBorder() method.

/*  w  ww .  ja  v a 2  s .  c  o  m*/
import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

public class Main extends JFrame {
  public Main() {
    getContentPane().setLayout(new FlowLayout());
    JLabel labelTwo = new JLabel("www.java2s.com");
    labelTwo.setBorder(BorderFactory.createCompoundBorder());
    
    add(labelTwo);
    
    
    JLabel labelThree = new JLabel("MatteBorder");
    labelThree.setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.pink));
    add(labelThree);
    
    
    JLabel labelFour = new JLabel("TitledBorder");
    labelFour.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(10, 10,
        10, 10, Color.pink), "Title", TitledBorder.RIGHT, TitledBorder.BOTTOM));
    add(labelFour);
    
    JLabel labelSix = new JLabel("CompoundBorder");
    Border one = BorderFactory.createEtchedBorder();
    Border two = BorderFactory.createMatteBorder(4, 4, 4, 4, Color.blue);
    labelSix.setBorder(BorderFactory.createCompoundBorder(one, two));
    add(labelSix);
    
  }

  public static void main(String[] args) {
    JFrame frame = new Main();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

  }
}