    01: import java.awt.*;
    02: import javax.swing.*;
    03:
    04: /**
    05:    An adapter that turns an icon into a JComponent.
    06: */
    07: public class IconAdapter extends JComponent
    08: {
    09:    /**
    10:       Constructs a JComponent that displays a given icon.
    11:       @param icon the icon to display
    12:    */
    13:    public IconAdapter(Icon icon)
    14:    {
    15:       this.icon = icon;
    16:    }
    17:
    18:    public void paintComponent(Graphics g)
    19:    {
    20:       icon.paintIcon(this, g, 0, 0);
    21:    }
    22:
    23:    public Dimension getPreferredSize()
    24:    {
    25:       return new Dimension(icon.getIconWidth(),
    26:             icon.getIconHeight());
    27:    }
    28:
    29:    private Icon icon;
    30: }