[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

BeanBox: ImageIcon doesn't show

Posted on 1998-02-22
1
Medium Priority
?
224 Views
Last Modified: 2012-06-21
Could anybody tell me why the following bean (packed in
a jar of course) doesn't show the icon my.gif in the BeanBox,
only the JTextField is visible. When I instantiate MyBean
in a program, put it into a container of type JComponent
both are visible, the icon as well as the textfield.
Somehow the icon get's lost in the beanbox.

I attached the code of the bean and the MANIFEST of
the affiliated jar. Maybe there is a problem with
the paths, maybe the icon must be specified as some
kind of resource in the manifest, or the icon some-
how gets painted over (it is there but I cannot see
it) ...????


import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.*;
import java.io.Serializable;


public class MyBean extends JPanel implements Serializable {
  JTextField textField;

  public MyBean() {
    setPreferredSize(new Dimension(300, 200));
    add(new JLabel(new ImageIcon("icons/my.gif")));
    textField = new JTextField(15);
    add(textField);
    textField.addKeyListener(new KeyAdapter() {
      ...
    });
  }

    /*public void paint(Graphics g) {
        g.setColor(beanColor);
        g.fillRect(20, 5, 20, 30);
    }*/

  public Dimension getMinimumSize() {
    return new Dimension(250, 100);
  }

  public void setString(String text) {
    textField.setText(text);
  }

  public String getString() {
    return textField.getText();
  }

  public Color getColor() {
    return beanColor;
  }

  public void setColor(Color newColor) {
    beanColor = newColor;
    repaint();
  }

  private Color beanColor = Color.blue;
}

-----------------------

Now for the manifest.mf:

Manifest-Version: 1.0

Name: MyBean.class
Java-Bean: True
Digest-Algorithms: SHA MD5
SHA-Digest: um+FrdYl5a3ZYMn/kXP1XzMgB+c=
MD5-Digest: mThC8cRAoDOAJ+w3Hpp0bQ==

Name: MyBean$1.class
Digest-Algorithms: SHA MD5
SHA-Digest: 6mMdpd/iW98NYJrgnf3bDUCp248=
MD5-Digest: TOfGXLJaAF8FzAOpZERvWA==

Name: icons/my.gif
Digest-Algorithms: SHA MD5
SHA-Digest: bn0lsJKG0RPy8QBUvLFgX4FfHHs=
MD5-Digest: D+tS5orsaKjInUE3W3rT1g==
0
Comment
Question by:Lewis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
russgold earned 600 total points
ID: 1233190
To show an icon in the BeanBox (or any bean builder for that matter), you must supply a BeanInfo class which defines the icon. In particular, you should subclass Java.beans.SimpleBeanInfo with a class named MyBeanBeanInfo which overrides the getIcon() method as follows:


public java.awt.Image getIcon(int iconKind) {
  java.awt.Image img = loadImage("icons/my.gif");
  return img;
  }


This assumes, of course, that your icon is the correct size.  You can use the iconKind parameter to select 16x16 icons or 32x32 icons.




0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question