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:
Image Movement using Swings
How to set the border in header and footer from login page using swings/awt
Advertisements
how to set background image
how to set size of button,textfield.
How to set attachment from browse button to send mails using java mail api
How to add a columns with a button set to a Jtable built with database result set
How to Give button tool tip image
How to Store Image using JSF
how to fetch image from mysql using jsp
How to Hide Button using Java Swing
How to put the logo in login form using swings/awt?
making of dynamic textfields using swings
another frame by using awt or swings
java code using swings
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
image on submit button
How to change image size before adding to mysql using jsp
How to search the selected item in row table using radia button in JSP?
how to create frame in swings
set background image in javafx
Regarding Image in Swings
An application using swings and vector methods
how to get data using dropdownlist, textbox and search button in jsp
How to insert image in sql database from user using servlet
how to access the object of one frame on clicking a button without using this keyword
How To Store Image Into MySQL Using Java
How to display image in jsp from database using Servlet?
how to store and retrieve image using struts2 and hibernate integration
making of dynamic textfields using swings

Ads