Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT how to set image in button using swing?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Senthil kumar
how to set image in button using swing?
1 Answer(s)      6 years and a month 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
 

 

 

DMCA.com