| | |
Drawing tree with JFrame
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 54
Reputation:
Solved Threads: 1
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?
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?
Just use JLabels for the nodes and override paintComponent() on your panel to render the lines between them.
•
•
Join Date: May 2008
Posts: 54
Reputation:
Solved Threads: 1
•
•
•
•
Just use JLabels for the nodes and override paintComponent() on your panel to render the lines between them.
•
•
Join Date: May 2008
Posts: 54
Reputation:
Solved Threads: 1
•
•
•
•
Just use JLabels for the nodes and override paintComponent() on your panel to render the lines between them.
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.
•
•
Join Date: May 2008
Posts: 54
Reputation:
Solved Threads: 1
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..
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..
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.
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.
•
•
Join Date: May 2008
Posts: 54
Reputation:
Solved Threads: 1
•
•
•
•
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.
![]() |
Other Threads in the Java Forum
- Previous Thread: Prefuse - build error
- Next Thread: receiving error "illegal start of expression"
| Thread Tools | Search this Thread |
Tag cloud for graphics







