![]() ![]()
|
20
Icon Creator
Features of JCIconCreator
Classes
Constructors and Methods
Examples
20.1 Features of JCIconCreator
There are times when you would like to have a custom image as part of your toolbars, labels, buttons, and so on, yet you don't want to go to the trouble of using a paint package.
JCIconCreatorlets you useStringarrays to create image icons. The advantages of usingJCIconCreatorinclude:
- A simple and convenient way of defining an image from a String of characters.
- Keeping the image information in the class that uses it, rather than having to manage the location of associated image files.
- Designing small-sized custom images or diagrams without the need of a paint program.
- Having a simple way of associating the image with the standard
javax.swing.ImageIconclass.
20.2 Classes
This utility consists of a single class,
com.klg.jclass.util.swing.JCIconCreator, subclassed fromjava.lang.Object.
20.3 Constructors and Methods
The
JCIconCreatorhas two constructors areJCIconCreator(), which creates an uninitialized image icon, andJCIconCreator(int w, int h), where the parameters measure the size, in pixels, of the two dimensional array used to hold the characters representing the image.Methods in JCIconCreator
The following is a list of the methods available for
JCIconCreator:
20.4 Examples
The following code section shows how to declare a
...Stringarray, use it as the source for defining the pixels in an icon, and how to convert theJCIconCreatorobject to anImageIconfor use as the graphic part of a label.
private static final String testIcon[] = {
" BBBBBBBBB ",
" B OOO B ",
" B OOOOO B ",
" B OOOOO B ",
" B OOOOO B ",
" B OOO B ",
" B B ",
" B B ",
" B B ",
" B B ",
" B B ",
" B B ",
" BBBBBBBBB " };
JButton b1;
public ToolbarIcons() {
JToolBar bar;
JLabel label;
setBackground(Color.lightGray);
setLayout(new BorderLayout());
JCIconCreator ic = new JCIconCreator(13, 13);
ic.setColor('B', Color.black);
ic.setColor('O', Color.orange);
ic.setPixels(testIcon);
ImageIcon icon = ic.getIcon();
...
bar = new JToolBar();
b1 = new JButton("Caution", icon);
bar.add(b1);
...
Figure 52 : Three labels with custom icons created using JCIconCreator.
![]() ![]()
|