how to set image in button using swing?

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.*;

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());
setTitle("Image on Button");

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {


For more information on Swing visit to :


Related Tutorials/Questions & Answers:
how to set image in button using swing? - Swing AWT
Image Movement using Swings
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 image - EJB
how to set size of button,textfield.
How to set attachment from browse button to send mails using java mail api
how to set a image in frame? - Swing AWT
How to add a columns with a button set to a Jtable built with database result set
How to Give button tool tip image
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
How I can Set Transparent Background Image to Panel - Java Beginners
set background image in javafx
How to Store Image using JSF
inserting image in mysql database using browse button in servlets
image on submit button
How to set iText pdf document background image - Java Beginners
how to fetch image from mysql using jsp
java code using swings
Regarding Image in Swings
How to Set Transperent Background Image to Jpanel - Java Beginners
making of dynamic textfields using swings
another frame by using awt or swings
how can i draw a table using applet or swings - Java Beginners
How to put the logo in login form using swings/awt?
UIImageView set Image URL
how to store data in table using swings - Java Beginners
How to Hide Button using Java Swing
How to set a variable value using velocity
How to change image size before adding to mysql using jsp
An application using swings and vector methods
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
Button with Image
How can we find the number of rows in a result set using PHP?
how to save uploaded image in database using javascript
How can i draw a line using java swings
How can i draw a line using java swings
How to set background of an excel sheet using POI - Java Magazine
how to set break in jasper report using ireport - JSP-Servlet
Press button and Scroll Image to Scrollpanel
How To Store Image Into MySQL Using Java
how to set the image and address in single row when genearting pdf fil from jsp - JSP-Servlet
making of dynamic textfields using swings
How to insert image in sql database from user using servlet
How to search the selected item in row table using radia button in JSP?
how to create frame in swings
how to store image in folder and stored image path in mysql database using JSP