• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

drawRect()

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm having trouble using the drawRect method. I'm using a JTabbedPane which calls the class FamilyTree which in turn calls the RectanglesCanvas class, not sure what i'm doing wrong.
Thanks.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The very first thing I noticed is that RectangleCanvas extends Canvas. This is an AWT component, and you are using Swing components in other places. This causes no end of problems, but is easy to fix. Instead of subclassing Canvas, just subclass JPanel, and change paint(Graphics) to paintComponent(Graphics).
 
Ritchie Partridge
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but the rectangles still don't seem to be displaying
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The line paintComponent(g); will cause an infinite loop right ? I think you want super.paintComponent( g );
D.
 
Ritchie Partridge
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Don,
But it still doesn't seem to return the panel.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post your latest code.
D.
 
Ritchie Partridge
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have cut out the middle class FamilyTree just to simplify it
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you posted doesn't appear to call draw() or drawRect() or anything of relevence...
 
Ritchie Partridge
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoops, posted the same file twice, here there are again:
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RectanglesCanvas.paintComponent draws the Rectangle it finds in the member variable "rect" of the enclosing class. But I don't see where this variable is ever initialzed -- i.e., it's null, so there's nothing to draw. Actually, you ought to be getting stack traces because of this.
 
Ritchie Partridge
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry meant to use the following:

Is there a scope problem with this?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, looking back through this thread, I don't see where you actually told us what the problem is we're trying to solve. Does this compile? Does it run but crash? Does it run but do nothing? Do some tabs work, but not others?
How about if you just stuff the RectanglesApplet into a JFrame, without the JTabbedPane and all the other stuff. Does it show up? What do you see?
 
Ritchie Partridge
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It compiles and runs, the other tabs work ok, but this tab is blank. I tried to simplify it too and it still shows up blank. Presume i'm accessing it wrong.
 
Ritchie Partridge
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone any ideas?
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic