Use BorderFactory to create line border in Java

Description

The following code shows how to use BorderFactory to create line border.

Example


import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
//from w w w. j  av a2s  . c  om
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

public class Main extends JFrame {

  public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));

    JLabel lineBorderLabel = new JLabel("Line Border", JLabel.CENTER);
    lineBorderLabel.setBorder(BorderFactory.createLineBorder(Color.black));
    simplePanel.add(lineBorderLabel);
    
    add(simplePanel);
  }
  public static void main(String[] argv) {
    Main borderFactoryDemo = new Main();

    borderFactoryDemo.setVisible(true);
    borderFactoryDemo.pack();
  }
}

The code above generates the following result.

Use BorderFactory to create line border in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer