We use cookies to collect and analyze information on site performance and usage,
to provide social media features and to enhance and customize content and advertisements.
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class TestJButton extends JApplet
{
JButton b1, b2, b3;
public void init() {
setLayout(new FlowLayout());
try {
b1 = new JButton("Regular",
new ImageIcon
(new URL("http://www.rgagnon.com/images/gumby.gif")));
add(b1);
// text on the center
b2 = new JButton("Special",
new ImageIcon
(new URL("http://www.rgagnon.com/images/gumby.gif")));
b2.setHorizontalTextPosition(SwingConstants.CENTER);
add(b2);
// text on the top
b3 = new JButton("Special",
new ImageIcon
(new URL("http://www.rgagnon.com/images/gumby.gif")));
b3.setVerticalTextPosition(SwingConstants.TOP);
b3.setHorizontalTextPosition(SwingConstants.CENTER);
add(b3);
}
catch (Exception e) {
e.printStackTrace();
}
}
}