how to set image in button using swing?

Ads
 

how to set image in button using swing?

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

Ads









Related Tutorials/Questions & Answers:
how to set image in button using swing? - Swing AWT
Image Movement using Swings
Advertisements
How to set the border in header and footer from login page using swings/awt
how to set background image
iPhone Button Image
how to set size of button,textfield.
how to set image - EJB
how to set a image in frame? - Swing AWT
How to set attachment from browse button to send mails using java mail api
How to Give button tool tip image
How to add a columns with a button set to a Jtable built with database result set
How to Store Image using JSF
How I can Set Transparent Background Image to Panel - Java Beginners
how to fetch image from mysql using jsp
How to set iText pdf document background image - Java Beginners
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
How to Hide Button using Java Swing
image on submit button
How to Set Transperent Background Image to Jpanel - Java Beginners
set background image in javafx
inserting image in mysql database using browse button in servlets
how can i draw a table using applet or swings - Java Beginners
how to set values in object using java and what are the ways?
how to show set of images continously using JScrollpane in java
how to show set of images continously using JScrollpane in java
How to put the logo in login form using swings/awt?
How to change image size before adding to mysql using jsp
how to save uploaded image in database using javascript
how to store data in table using swings - Java Beginners
How to set a variable value using velocity
How can we find the number of rows in a result set using PHP?

Ads