Custom container? how?

Hello, i created this panel:

public class ImagePanel extends JPanel {

protected Image backgroundImage;
protected String backgroundURI;
protected Dimension preferredSize;

public ImagePanel( int width, int height ){
preferredSize = new Dimension(width,height);

public Image getBackgroundImage() {
return backgroundImage;

public void setBackgroundImage(Image backgroundImage) {
this.backgroundImage = backgroundImage;

public String getBackgroundURI() {
return backgroundURI;

public void setBackgroundURI(String backgroundURI) {
this.backgroundURI = backgroundURI;
Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
this.backgroundImage = tk.getImage(backgroundURI);

public void paint (Graphics g) {

Image i = this.backgroundImage;

if( i != null ){

int h = i.getHeight(null), w = i.getWidth(null);

java.awt.Color c = this.getBackground();

g.drawImage(i, h, w, c, null);


public Dimension getPreferredSize() {
return preferredSize; //To change body of overridden methods use File | Settings | File Templates.

and i added as a custom component, the 'is conatiner' is checked.
I add it to a panel, but i can add component inside my component, but it's a container
How can i resolve this?


i'm using idea build 6141

Please sign in to leave a comment.