Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom AWT Component not rendering more than one instance

 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doh! It was the add method?I'm a fool!

Thanks for your time!!
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still haven't figured the thing out but at least I found some stuff I can change
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic