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

 
 


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

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.