• Post Reply Bookmark Topic Watch Topic
  • New Topic

BorderLayout question  RSS feed

 
Larry Eisenstein
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a problem that seems simple, but I've been looking at it for over an hour and can't figure it out.

I downloaded some code from a Java2D site,
http://www.java2s.com/ExampleCode/2D-Graphics-GUI/Mousedraganddroptodraw.htm

The program works just like the picture, but I can't figure out why the Coordinates are displayed in the top corner too. I see where the coordinated are added to the panel and put in BorderLayout.SOUTH, but I don't see where they are added to the top of the drawing canvas.

What am I missing here?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not; it's just an artifact due to broken code. You're not supposed to override the paint() method of a Swing component, but rather the paintComponent() method. Overriding paint() is leading to some painting errors where that label appears to be rendered in more than one place.

If you change the "public void paint(Graphics..." to "public void paintComponent(Graphics..." this problem should disappear. And then please be careful where you get your sample code from in the future!
 
Larry Eisenstein
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed it, and the coordinates were still there, but that did fix another issue with the setBackground. Point taken about online code.

Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!