dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Oct 26, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Swing, Images on Buttons

Swing makes it easy to place an image on just about any component. To see an image on a button, substitute the path and file name of an image on your hard drive in place of the gif file shown in the code below. This code was tested using JDK1.1.6 and Swing 1.0.3 under Win95:
 
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;

public class SwingImageOnButton01 extends JFrame {
	ImageIcon theIcon = new ImageIcon(
		 "c:/baldwin/JavaProg/Combined/Java/images/bulb2.gif");

	public static void main(String args[]) {
		new SwingImageOnButton01();
	}//end main()
	//-----------------------------------------------------//
  
	SwingImageOnButton01() {//constructor
		//Create the JButton object with a normal icon
		JButton myJButton = new JButton("JButton", theIcon);

		getContentPane().setLayout(new FlowLayout());
		getContentPane().add(myJButton);
		setTitle("Image on Button");
		setSize(300,100);
		setVisible(true);
    
		// Inner class WindowAdapter terminates the
		// program when the JFrame is closed.
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);}});//end WindowListener
    
	}//end constructor
}//end class SwingImageOnButton01
Richard G.
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date