Set Margin for JButton in Java
Description
The following code shows how to set Margin for JButton.
Example
import java.awt.Insets;
//from w ww .j a va2 s . c o m
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main extends JFrame {
public Main() {
setSize(300, 150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton button = new JButton("java2s.com");
button.setMargin(new Insets(20, 20, 20, 20));
add(button);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »