In this section, you will studied how to display a single icon one or more times in a row.
An icon is an image, picture, or representation. To display the icon, we have defined an image. The class ImageIcon is responsible to paint the icons from Images. The MediaTracker preloads the images that are created from a URL, filename or byte array.
The variable space is defined to set the space between the images. The method createEmptyBorder(this.space, this.space,this.space, this.space) creates an empty border that takes up space. The class Insets defines the borders of a container which specifies the space at each of its edges that a container must leave .
The method getPreferredSize() is used to determine how the layout should be arranged. The method getClipBounds() gets a rectangle and encloses the clipping region of the Graphics object. To give the blending and transparency effects with graphics and images for combining source and destination pixels, the class AlphaComposite is used.
Following code returns an ImageIcon:
| protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = IconDisplayerExample.class.getResource(path); return new ImageIcon(imgURL); } |
Here is the code of IconDisplayerExample.java
import java.awt.*;
|
Output will be displayed as:
![]()
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.
Ask Questions? Discuss: Show Icon Displayer
Post your Comment