Home Java Example Java Swing Setting icon on the button in Java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Setting icon on the button in Java

Advertisement
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.

Advertisement

Liked it!  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.

Posted on: April 14, 2007

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
 
 
Comments
preethi
May 31, 2011
seeting bounds

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

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 .
venky
April 10, 2012
gud

hi... working nice program
DMCA.com