Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Drawing not displayed on JPanel  RSS feed

 
Scott Krasnigor
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to draw a binary tree on a JPanel. I subclassed JPanel and overrided the paintComponent method. However, my nodes aren't being drawn. When the application starts, there is no tree to display and text is displayed in the window asking to load a new tree. This part is working. But when I load a tree, I just get a blank panel. The paintComponent method and the drawNode method is listed below. Sorry if the code doesn't format properly - first time.

 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you minimize and restore the window, it the tree drawn then? If so,
you need to call repaint after reading the tree.
 
Scott Krasnigor
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nope. no sign of the nodes. The initial text that was displayed is cleared but the nodes don't appear.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is complicated. Can you post a complete minimal example program that demonstrates your problem?
 
Scott Krasnigor
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved it. The dimensions of the nodes were not being calculated correctly. The nodes were being drawn with a size of zero. I changed how the dimension of the JPanel is obtained (which is used to calculate the dimensions of the tree and it's nodes) and that fixed the problem. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!