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.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »