ButtonBorderTest.java Source code

Java tutorial

Introduction

Here is the source code for ButtonBorderTest.java

Source

import java.awt.BorderLayout;
import java.awt.Container;

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

public class ButtonBorderTest {
    public static void main(String args[]) {
        JFrame frame = new JFrame("Fourth Button");
        Container contentPane = frame.getContentPane();
        Icon icon = new ImageIcon("java2s.gif");
        JButton b = new JButton("Button!");
        Border bored = BorderFactory.createMatteBorder(10, 5, 10, 5, icon);
        b.setBorder(bored);
        contentPane.add(b, BorderLayout.CENTER);
        frame.setSize(350, 200);
        frame.show();
    }
}