Share on Google+Share on Google+

Setting icon on the button in Java

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:

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("");
  Icon imgicon = new ImageIcon("icon_confused.gif");
  JPanel panel = new JPanel();
  frame.add(panel, BorderLayout.NORTH);

Download this example.



Posted on: April 14, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

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

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
May 31, 2011
seeting bounds

how to set bounds for an "icon on button"????? pls respond
June 13, 2013

Does seem a little despreate. The LAST thing any professional looks at on an NLE is the logo design I'm happy to work on AVID or FCP they basically do the same thing, the main difference is the operator.Bottom line however, is price even with deep price cuts, AVID cannot compete as they have a layer of dealers to cut into the equation, wanting maintenance contracts and to sell overpriced shared storage systems to counteract the lower headline' costs of the seats.BTW, anyone criticising AVIDs support would do well to look at Apple's appaling pro tech support, and although AVID have a rep for charging big bucks for tardy upgrades, Apple is WELL behind with a new version of FCStudio, and is in danger of losing market share from it unless it acts soon.I think the next few months will tell whether or not Apple is serious about pro users any more, or whether it's just an iPod maker these days .
April 10, 2012

hi... working nice program