Drawing tree with JFrame

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 54
Reputation: gangsta1903 is an unknown quantity at this point 
Solved Threads: 1
gangsta1903 gangsta1903 is offline Offline
Junior Poster in Training

Drawing tree with JFrame

 
0
  #1
Oct 14th, 2008
I want to draw a tree in Jframe, the tree view is available in the attachment,

As you see there are nodes connecting to each other.I know that I have to find the midpoint of the nodes at the same level or things like that.

What I want your help is which components Should I use?
the necessities are:
No third parties,just using swing,
a node can be clicked to add or remove node,when clicked a textbox will be opened and the user will enter name of node,and if the tree gets bigger and doesnt fit the window the window will be able to expand.

Some says that I must use JScrollpane for window.But I dont have a main idea!


Is there anyone who can help me?
Attached Thumbnails
Untitled-1.jpg  
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,500
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Drawing tree with JFrame

 
0
  #2
Oct 14th, 2008
Just use JLabels for the nodes and override paintComponent() on your panel to render the lines between them.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 54
Reputation: gangsta1903 is an unknown quantity at this point 
Solved Threads: 1
gangsta1903 gangsta1903 is offline Offline
Junior Poster in Training

Re: Drawing tree with JFrame

 
0
  #3
Oct 14th, 2008
Originally Posted by Ezzaral View Post
Just use JLabels for the nodes and override paintComponent() on your panel to render the lines between them.
thanks
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 54
Reputation: gangsta1903 is an unknown quantity at this point 
Solved Threads: 1
gangsta1903 gangsta1903 is offline Offline
Junior Poster in Training

Re: Drawing tree with JFrame

 
0
  #4
Oct 15th, 2008
Originally Posted by Ezzaral View Post
Just use JLabels for the nodes and override paintComponent() on your panel to render the lines between them.
I have created a JFrame frame and a Jpanel panel,
then I added the panel to frame.

I have overriden paintComponent method in my panel.
Now,do I have to call paintComponent method on Jpanel object?
Because it shows nothing but the background.
Last edited by gangsta1903; Oct 15th, 2008 at 1:11 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,500
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Drawing tree with JFrame

 
0
  #5
Oct 15th, 2008
paintComponent() is called automatically when your component needs to be rendered. If you haven't put anything on the panel then it's showing you exactly what is there: nothing.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 54
Reputation: gangsta1903 is an unknown quantity at this point 
Solved Threads: 1
gangsta1903 gangsta1903 is offline Offline
Junior Poster in Training

Re: Drawing tree with JFrame

 
0
  #6
Oct 15th, 2008
no,of course I put my drawing function in paintComponent! but it doesnt show anything!

As far as I see,there is no probelm with Jpanel or Jframe,maybe my drawing method in overriden paintComponent method can be the problem.But I cannot debug,because debeugger does not enter paintComponent,although I put breakpoint inside it...

I am using eclipse 3.4.1,please help me..
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,500
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Drawing tree with JFrame

 
0
  #7
Oct 15th, 2008
I don't use Eclipse, but it's debugger should enter paintComponent() just fine.

I'd recommend starting with one of the basic drawing examples from the 2D tutorial that I linked above and then modifying the drawing code to draw the lines you want. Once you understand the rendering process of the components and the use of the Graphic2D class more clearly you'll be in better shape to apply that to your specific application needs.
Last edited by Ezzaral; Oct 15th, 2008 at 1:41 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 54
Reputation: gangsta1903 is an unknown quantity at this point 
Solved Threads: 1
gangsta1903 gangsta1903 is offline Offline
Junior Poster in Training

Re: Drawing tree with JFrame

 
0
  #8
Oct 15th, 2008
Originally Posted by Ezzaral View Post
I don't use Eclipse, but it's debugger should enter paintComponent() just fine.

I'd recommend starting with one of the basic drawing examples from the 2D tutorial that I linked above and then modifying the drawing code to draw the lines you want. Once you understand the rendering process of the components and the use of the Graphic2D class more clearly you'll be in better shape to apply that to your specific application needs.
Is there any way for panel to draw without overriding paintComponent method?Can I put my method just in Jpanel and then call it?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 54
Reputation: gangsta1903 is an unknown quantity at this point 
Solved Threads: 1
gangsta1903 gangsta1903 is offline Offline
Junior Poster in Training

Re: Drawing tree with JFrame

 
0
  #9
Oct 15th, 2008
now,I found the problem,its not about the overriden method!

now there is something new,
You suggested me to use Jlabels ,but I used drawRectangle to draw nodes.Can these nodes(shapes) be clickable? Or do I have to use Jlabels?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,500
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Drawing tree with JFrame

 
0
  #10
Oct 15th, 2008
Call it how? It needs a graphic context, which is supplied by the paintComponent() method when the component is rendered to the screen.

Edit: Cross-post. I'm referring to the previous question on calling the method yourself.
Last edited by Ezzaral; Oct 15th, 2008 at 2:04 pm.
Reply With Quote Quick reply to this message  
Reply

Tags
graphics

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for graphics
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC