Change JButton Border in Java

Description

The following code shows how to change JButton Border.

Example


  // w ww.  ja  va2 s.  co m
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.Border;

public class Main {
  public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    JButton b = new JButton("Button!");
    Border bored = BorderFactory.createLineBorder(Color.RED);
    b.setBorder(bored);
    contentPane.add(b, BorderLayout.CENTER);
    frame.setSize(350, 200);
    frame.setVisible(true);
  }
}

The code above generates the following result.

Change JButton 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