createImage problem

P

patrick

Im trying to create an Image like this:

class A extends JPanel
{
public A()
{
//set up a panel
...

Image im=createImage(50,100);
}
}

creatImage returns null for image when i run it thro debugger.

Any idea what the problem is ??

thanks
patrick
 
A

Andrew Thompson

patrick said:
Im trying to create an Image like this:

class A extends JPanel
{
public A()
{
//set up a panel
...

Image im=createImage(50,100);
}
}

creatImage returns null for image when i run it thro debugger.

Any idea what the problem is ??

Probably all the code you did not include!!
 
P

patrick

class A extends JPanel
{ public A()
{
//set up a panel
setLayout(new BorderLayout());
setBorder(BorderFactory.createRaisedBevelBorder());
setBounds(100,200,200,200);

Image im=createImage(50,100);
}
}


The above is the only code ive got in it of any relevance.

patrick



setBorder(BorderFactory.createRaisedBevelBorder());
setBounds(100,200,200,200);//sets > >
 
A

Andrew Thompson

patrick said:
class A extends JPanel
{ public A()
{
//set up a panel
setLayout(new BorderLayout());
setBorder(BorderFactory.createRaisedBevelBorder());
setBounds(100,200,200,200);

Image im=createImage(50,100);
}
}


The above is the only code ive got in it of any relevance.

OK... this is like pulling teeth.

Cut your code down to the (I get sick of saying this)
smallest, self contained, compileable example that
displays the problem. Post that.

[ Unless I misunderstand you and the above is the
_only_ code you have.. ]

Also..
Your words are not entirely clear to me - when you
say 'debugger', do you mean running the code, or
compiling it?

What is the _exact_ message or stacktrace?
copy and paste it.
 
P

patrick

ive compiled and run the debugger in JBuilder with this exact code.
im is null after getting past the line: Image im=createImage(50,100);
There is no message since there is no error.But if I try to use im I will
get a NullPointerError


class Ab extends JPanel
{
public Ab()
{
//set up a panel
// ...
setLayout(new BorderLayout());
setBorder(BorderFactory.createRaisedBevelBorder());
setBounds(100,200,200,200);

Image im=createImage(50,100);
}
}

patrick



Andrew Thompson said:
patrick said:
class A extends JPanel
{ public A()
{
//set up a panel
setLayout(new BorderLayout());
setBorder(BorderFactory.createRaisedBevelBorder());
setBounds(100,200,200,200);

Image im=createImage(50,100);
}
}


The above is the only code ive got in it of any relevance.

OK... this is like pulling teeth.

Cut your code down to the (I get sick of saying this)
smallest, self contained, compileable example that
displays the problem. Post that.

[ Unless I misunderstand you and the above is the
_only_ code you have.. ]

Also..
Your words are not entirely clear to me - when you
say 'debugger', do you mean running the code, or
compiling it?

What is the _exact_ message or stacktrace?
copy and paste it.

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
 
T

Thomas Weidenfeller

patrick said:
Any idea what the problem is ??

There is none. This is documented behavior (see the API
documentation). Unless you have specific double-buffering needs,
forget about createImage(). Instead, consider e.g. a BufferedImage.

If you really want to use createImage(), delay the call until you are
in the paint[Component]() method call.

/Thomas
 
M

Michael Borgwardt

patrick said:
ive compiled and run the debugger in JBuilder with this exact code.
im is null after getting past the line: Image im=createImage(50,100);
There is no message since there is no error.

So read the *fucking* API documentation for the createImage()
method already!!!
 
J

johnR

Im trying to create an Image like this:
class A extends JPanel
{
public A()
{
//set up a panel

Image im=createImage(50,100);
}
}

creatImage returns null for image when i run it thro
debugger.
Any idea what the problem is ??


You should call 'createImage(50,100)' AFTER you've made
your JPanel up and running (visible). That'll do the trick.
 
P

patrick

Thanks for all the replies. the BufferedImage solved my problem finally

patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top