aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Custom AWT Component not rendering more than one instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Custom AWT Component not rendering more than one instance " Watch "Custom AWT Component not rendering more than one instance " New topic
Author

Custom AWT Component not rendering more than one instance

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Hi all,

I have a custom AWT component that I've written.The component works perfectly---as long as I dont use more than one at a time.Please could someone advise where I might be going wrong?In the example below only the 3rd 't instance' is rendered.Also, from the logging that I put in I can see that at the time that g.drawImage is called, that the values for x and y do not correspond to the correct object..



Output from my logging:
sun.awt.image.FileImageSource@47b480
Constructor::this.x::0
Constructor::this.y::0
sun.awt.image.FileImageSource@19b49e6
Constructor::this.x::100
Constructor::this.y::100
sun.awt.image.FileImageSource@10d448
Constructor::this.x::200
Constructor::this.y::200
COMPLENGTH:3
diagram !=null
rectangle != null
=======>START Paint
text fits
Drawing image at200,200
=======>END Paint
=======>START Paint
diagram !=null
rectangle != null
text fits
Drawing image at200,200
=======>END Paint
diagram !=null
rectangle != null
text fits
Drawing image at200,200
=======>START Paint
=======>END Paint

===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The default LayoutManager for Frame is BorderLayout. Calling the one-argument add() method will always place the component in the BorderLayout.CENTER position, replacing any previous component in that location.

To show three components, you could use a FlowLayout -- i.e., include

f.setLayout(new FlowLayout());

right before the f.add() calls.

[Jess in Action][AskingGoodQuestions]
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

doh! It was the add method?I'm a fool!

Thanks for your time!!
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Still haven't figured the thing out but at least I found some stuff I can change
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Custom AWT Component not rendering more than one instance