Creating Image Buttons with javax.swing.JButton Class

This section provides a tutorial example on how to create an image button with the JButton class and the ImageIcon class.

You can also create a button with your own image. Here is a sample program:

 * Copyright (c) 1997-2018 All Rights Reserved.
import java.awt.*;
import javax.swing.*;
public class JButtonIcon {
   public static void main(String[] a) {
      JFrame f = new JFrame("My Icon Button");
      JButton b = new JButton(new ImageIcon("java.gif"));

If you run this example, you will get:

JLabel Image Icon Button
JLabel Image Icon Button

Note: The ImageIcon class is used to create a button with an image.

Table of Contents

 About This Book

 JDK (Java Development Kit)

 Introduction of Java Swing Package

 Graphics Environment of the Local System

 JFrame - Main Frame Class

 JLabel - Swing Label Class

JButton - Swing Button Class

 Creating Buttons with javax.swing.JButton Class

Creating Image Buttons with javax.swing.JButton Class

 Button Action Handler at the Component Level

 Button Action Handler at the Frame Level

 Mouse Click Handler at the Frame Level

 JCheckBox - Swing Check Box Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 JComboBox - Swing Combo Box Class

 Menu Bar, Menus, Menu Items and Listeners

 Creating Internal Frames inside the Main Frame

 Layout of Components in a Container

 LookAndFeel and UIManager

 Option Dialog Boxes

 JEditorPane - The Editor Pane Class

 SwingWorker - The Background Task Worker

 AWT (Abstract Windows Toolkit)

 Integration with Desktop System

 Archived Tutorials


 Full Version in PDF/EPUB