Bean Icon in Form Editor

I created a very basic JLabel Bean, which I would like to see in the Form Editor with a custom image (like DBTreeView). I tried the setIcon() method of the JLabel, called in the constructor of my Bean, but this seems to have no effect. Searched in the DBTreeView sources as well, but could not find something for this particular case. Is this Servoy magic or are there public API calls for this?

Do you mean the icon that you can see in the plugins node of the Solution Explorer ?
If so you need to create a plugin for this.

No, i mean the image, which you can see when you put a DBTreeView in your form via Form Editor. Like the image attached to this post.

felix.willnecker:
No, i mean the image, which you can see when you put a DBTreeView in your form via Form Editor. Like the image attached to this post.

This is not an IconImage you see here, but a real tree based on dummy values (SwingDBTree is a JTree subclass).
The bean is disabled in the form editor, but the rendering is done by the JTree.

I see, so I changed my Bean to a JPanel sublcassed Bean, which holds two properties.

protected java.awt.Image						image				= null;
protected java.net.URL						imageURL			= null;

My images are stored in subpackage so I can load them in the constructor with this code:

public iBizNormalViewDesign(IClientPluginAccess application) {
		super(application);
		this.imageURL = this.getClass().getResource("images/normalview.png");
		image = Toolkit.getDefaultToolkit().createImage(this.imageURL);

		if(imageURL == null) {
			logger.error("images/normalview.png not found");
		} 
	}

Then it is easy to draw the image, with the paintComponent() method.

public void paintComponent(Graphics g) {
		logger.trace("paint component called");
		super.paintComponent(g);
		if (this.image != null) {
			if (this.image.getWidth(null) < 0) {
				this.image = new ImageIcon(this.imageURL).getImage();
			}
			if ((this.getWidth() < image.getWidth(null)) || (this.getHeight() < image.getHeight(null))) {
				g.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null), null);
			} else {
				g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);
			}
		}

This code makes sure, that the image is loaded correctly and scales the image, to the right size. There seem to be some problems, when the bean is too small. So far this works, i’ll post an update if I created a better method for drawing.