BorderFactory: createLineBorder(Color color) : BorderFactory « javax.swing « Java by API






BorderFactory: createLineBorder(Color color)

 
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

public class Main {
  public static void main(String[] args) {
    JLabel label1 = new JLabel("BottomRight", SwingConstants.RIGHT);
    JLabel label2 = new JLabel("CenterLeft", SwingConstants.LEFT);
    JLabel label3 = new JLabel("TopCenter", SwingConstants.CENTER);
    label1.setVerticalAlignment(SwingConstants.BOTTOM);
    label2.setVerticalAlignment(SwingConstants.CENTER);
    label3.setVerticalAlignment(SwingConstants.TOP);

    label1.setBorder(BorderFactory.createLineBorder(Color.black));
    label2.setBorder(BorderFactory.createLineBorder(Color.black));
    label3.setBorder(BorderFactory.createLineBorder(Color.black));

    JFrame frame = new JFrame("AlignmentExample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel(new GridLayout(3, 1, 8, 8));
    p.add(label1);
    p.add(label2);
    p.add(label3);
    p.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    frame.setContentPane(p);
    frame.setSize(200, 200);
    frame.setVisible(true);
  }
}

   
  








Related examples in the same category

1.BorderFactory: createBevelBorder(int type,Color highlight,Color shadow)
2.BorderFactory: createCompoundBorder(Border outsideBorder, Border insideBorder)
3.BorderFactory: createEtchedBorder()
4.BorderFactory: createEmptyBorder(int top,int left,int bottom,int right)
5.BorderFactory: createLineBorder(Color color, int thickness)
6.BorderFactory: createLoweredBevelBorder()
7.BorderFactory: createMatteBorder(int top, int left, int bottom, int right, Color color)
8.BorderFactory: createRaisedBevelBorder()
9.BorderFactory.createTitledBorder(String text)
10.BorderFactory: createTitledBorder(Border b, String t, int j, int p)