Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to createImage(w,h) in JFrame constructor?

46 views
Skip to first unread message

Cynthia Marat

unread,
Aug 31, 2000, 4:49:53 PM8/31/00
to
Hello,

I need to create an ImageIcon of 20 by 20 pixels
of a plain color which could be changed from time to time.

The solution is to do the following statement:
new ImageIcon(Image image);

In order to create Image of changeable colors,
I need to use createImage(int width, int height)
and having so:

Image icon = new ImageIcon( createImage(20,20) );

later on, I can change the color as:

Graphics ig = GroupingFrame.icon.getImage().getGraphics();
ig.setColor(color);
ig.fillRect(0,0, 15,15);
setIcon(icon);

This does not work as I need the icon instance during the JFrame construction
(ListCellRenderer's getListCellRendererComponent)

getToolkit does not work either.

Thanks
Cynthia


Laurent Lequenne

unread,
Sep 1, 2000, 5:23:39 AM9/1/00
to
Here is what I found :)

Hello

If you take a look inside the createImage(int, int) method of class
Component (See next snip) you will see that it use the peer
Component...In case that your peer dosen't exist --->peer=null; the
result of the method call is null after the next instruction:
return (peer != null) ? peer.createImage(width, height) : null;

More about peer components:

A peer component is created when the component is displayed for the
first time on the screen or when the component is added on the
container which is also a peer.. . A peer component is a platform
dependent GUI component created by JVM to use the same look and feel
as the user of the concerning paltform is used with....So it is a
intermediate level between JVM and the specific platform... The bad
part is that you can not have transparent peer components and the
communication between user-component is slower.. The solution si to
create lightweight components (directly extend class Component or use
Swing components-the new generation of Java GUI components)..

(As I know-If anybody else has other
knowledge about the peer creation and about peer component -please
let us know..)

......
public Image createImage(int width, int height) {
ComponentPeer peer = this.peer;
if (peer instanceof java.awt.peer.LightweightPeer) {
return parent.createImage(width, height);
} else {
return (peer != null) ? peer.createImage(width, height) : null;
}
}
...........

My best wishes
Calin
_______________________________________

"Cynthia Marat" <c_m...@mypad.com> wrote in message
news:39AEC4F1...@mypad.com...

0 new messages