Senthil kumar
how to set image in button using swing?
1 Answer(s)      6 years and 9 months ago
Posted in : Swing AWT
Advertisement
View Answers

December 2, 2008 at 1:40 AM


Hi friend,

import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;

public class ImageButton extends JFrame {
ImageIcon theIcon = new ImageIcon("image.gif");

public static void main(String args[]) {
new ImageButton();
}

ImageButton() {
JButton myJButton = new JButton("JButton", theIcon);

getContentPane().setLayout(new FlowLayout());
getContentPane().add(myJButton);
setTitle("Image on Button");
setSize(300,100);
setVisible(true);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);}});

}
}

For more information on Swing visit to :

http://www.roseindia.net/java/example/java/swing/

Thanks









Related Tutorials/Questions & Answers:
Advertisements