Home Java Example Java Swing Setting icon on the button in Java



Setting icon on the button in Java
Posted on: April 14, 2007 at 12:00 AM
This section illustrates you how to show the icon on the button in Java Swing.

Setting icon on the button in Java

     

This section illustrates you how to show the icon on the button in Java Swing.

This program sets the icon on the button in Java Swing. 

Following is the output of the program:

Icon on Button

Code description:

setIcon(Icon):
Above method sets the specified Icon on the button.

ImagIcon(String image_name):
Above code creates an object of image.

Here is the code of the program:

import javax.swing.*;
import java.awt.*;

public class IconButton{
  public static void main(String[] args){
  JFrame frame = new JFrame("Icon on button");
  JButton button = new JButton("Roseindia.net");
  Icon imgicon = new ImageIcon("icon_confused.gif");
  JPanel panel = new JPanel();
  button.setIcon(imgicon);
  panel.add(button);
  frame.add(panel, BorderLayout.NORTH);
  frame.setSize(400400);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

Related Tags for Setting icon on the button in Java:
javacswingbuttoniohelpiconthisshowexamplewithtoexamsheilitsectioninmtrjesicohowrateratesxaxampsatisllmplstrwingvattssthshoswavstpleplono


More Tutorials from this section

Ask Questions?    Discuss: Setting icon on the button in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.