• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BorderLayout question

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic