Forums Register Login

Tree and drawing within the same panel

+Pie Number of slices to send: Send
I want to place both the tree and my drawing with in the same panel..I used borderlayout..But its getting overlap..How can i do it..Help me..
+Pie Number of slices to send: Send
 

Originally posted by shalini gnana:
I want to place both the tree and my drawing with in the same panel..I used borderlayout..But its getting overlap..How can i do it..Help me..



If your drawing is an image you can override the paintComponent of the panel and draw the image as the background. For this to be visible you will have to make all the components (tree, viewport, scrollpane etc) which go into this panel, transperant.
+Pie Number of slices to send: Send
I want my tree at the left side of my panel and drawing at the centre without overlaping each other..
+Pie Number of slices to send: Send
How do you create the drawing? Have you overridden the paint or paintComponent from the same panel that you are adding the tree to?

If so, try putting that drawing code in a different panel, and add that panel to the first panel using BorderLayout.CENTER.
+Pie Number of slices to send: Send
I don't want to do it in that way because i want to add scrollBars to it, that either the drawing area and the tree scroll simultaneously..


+Pie Number of slices to send: Send
Then you have to calculate the width of the tree, and only start painting at that border. Instead of starting at x = 0, you start at x = tree.getX() + tree.getWidth().
+Pie Number of slices to send: Send
No i'm not getting you..Where should i have to perform this calculation?
+Pie Number of slices to send: Send
In the code where you paint your drawing.
+Pie Number of slices to send: Send
I still don't understand why this has to be done all in the same panel...

it would be a lot simpler to just make the component that is painting one component, add it to the BorderLayout.CENTER of a panel, add the tree to the BorderLayout.WEST/EAST whatever, and then add this panel to a JScrollpane. Then they would both scroll together, and you wouldn't have to do all this wacky stuff to try to get around the layout managers.



Alternatively, if you want the tree and drawing to scroll separately, add the tree to a scrollpane, add the drawing to another scrollpane, and add the scrollpane containing the drawing to BorderLayout.CENTER of the panel, and add the scrollpane containing the tree to to BorderLayout.WEST/EAST.

+Pie Number of slices to send: Send
I drawn inside the paintComponent method..How can i add this to the east of my borderlayout?
I want to add both tree and drawing to the same panel,because when i expand my tree the drawing against to the child should show...And my requirement is so...


[ October 25, 2007: Message edited by: shalini gnana ]
+Pie Number of slices to send: Send
Any Help?
+Pie Number of slices to send: Send
Its throwing NullPointException at: rightPanel.add(tree,BorderLayout.WEST);





+Pie Number of slices to send: Send
 


I drawn inside the paintComponent method..How can i add this to the east of my borderlayout?



As above - separate this into parent and child panels - have the child panel provide the drawing (paintComponent), and have the parent panel provide the layout.


I want to add both tree and drawing to the same panel,because when i expand my tree the drawing against to the child should show...



That would normally be done using TreeSelectionListener - you could make your drawing component implement TreeSelectionListener, add it as a listener to the tree, and react to the tree expansion events by determining what child node needs to be repainted and repainting the drawing component.


Its throwing NullPointException at: rightPanel.add(tree,BorderLayout.WEST);



I don't see the "tree" variable being initialized anywhere in the code provided.

Here's an example of how to pull this all together -


(Edit - changed TreeExpansionListener to TreeSelectionListener in explanation. Posted example code.)
[ October 25, 2007: Message edited by: Nathan Pruett ]
+Pie Number of slices to send: Send
Thank you..Now my tree is displaying inside the panel..But,now the issue is,i added scrollbar to my panel..But its not showing..What might be the reason?
+Pie Number of slices to send: Send
Thanks alot for your help..
Infact that is not my reruirement...
I want to produce a gantt chart for task scheduling,my requirement is...the task 'll be in the tree and the dates 'll be given in top of the panel as single row..I'll draw filled rectangle against the task and date..Now the problem is if the task is selected the all the rectangles should show or it should not...How to achieve it? Is it possible to do


[ October 26, 2007: Message edited by: shalini gnana ]
+Pie Number of slices to send: Send
I want to draw against particular node..How can i do that?
+Pie Number of slices to send: Send
Any help..please..
+Pie Number of slices to send: Send
I want to draw the rectangle against the node which is selected...
Can anyone,help me...
+Pie Number of slices to send: Send
Sounds like a "TreeTable" - there's an example of how to create a TreeTable yourself on Sun Developer Network. The JDesktop project also provides a JTreeTable implementation.
+Pie Number of slices to send: Send
No,I don't want to do it in that way..I want to draw in my drawing area..Please,help me...
+Pie Number of slices to send: Send
I've changed my previous example slightly - I've added a JScrollPane at the top level, and also taken the y location of the selected child into account in the "Drawing" component.

+Pie Number of slices to send: Send
Thanks alot..Instead of drawstring i used drawrect,But,now the problem is the drawing have to be repainted(i.e., it should not show) only when the node gets collapsed...Is their any method to do so? Please help me?
+Pie Number of slices to send: Send
Anyhelp,please
+Pie Number of slices to send: Send
In the public void valueChanged(TreeSelectionEvent e) method of TreeSelectionListener, you can call e.isAddedPath() to determine if the event is a selection or deselection event. You can get the parent node from the TreePath using path.getParentPath().
+Pie Number of slices to send: Send
THANKS ALOT...I'll try it out....
+Pie Number of slices to send: Send
I want to drawline against the parent node when its expanded....But its not showing any line...
How can i draw for each node?
Please help me..

+Pie Number of slices to send: Send
Please help me..
+Pie Number of slices to send: Send
It sounds like you need to do a lot more processing on this than just the location of the original child. Instead of just the Y location of the selected child, you'll need to use the TreePath of the currently selcted child to get:
  • that child's parent node;
  • all the children nodes of that parent.

  • Then, make TreePaths of all these nodes to get their coordinates to draw the line/rectangle as you need to.
    +Pie Number of slices to send: Send
    I'm not getting what you are trying to say...
    Can you explain me,please..
    +Pie Number of slices to send: Send
     


    tree.putClientProperty("JTree().lineStyle","Horizontal");



    I tried the above thing in my code but i'm not getting it?Help me...

    +Pie Number of slices to send: Send
    It's tree.putClientProperty("JTree.lineStyle", "Horizontal"); (no parentheses after the "JTree" property)

    And this changes how the lines that connect nodes are drawn within the tree - I thought that you wanted to draw lines on the "Drawing" panel?
    +Pie Number of slices to send: Send
    Yes,i need to do that too...Can you explain me little bit elobrately how to draw at each node?
    Please help me...
    +Pie Number of slices to send: Send
    Is there any way i can achieve it?
    +Pie Number of slices to send: Send
     


    how to draw at each node





    If you want to draw *in* the tree node, you'd need to create a TreeCellRenderer.

    If you want to draw *in* the DrawingPanel at the location of a node, you'll need to get the TreePath to that node, call tree.getPathBounds(path) to get the bounding rectangle of that path - that will get you coordinates for that node you can use to draw in the DrawingPanel. If you have a TreePath of one node, you can get the TreePath of it's parent node by calling path.getParentPath(). If you're using a DefaultTreeModel, you can call path.getLastPathComponent() and cast the result to a TreeNode. You can then call node.children() to get an Enumeration of all the children. You can create a new TreePath to each child by using the parent TreePath and creating a new TreePath with the parent path and the child node - TreePath childPath = new TreePath(parentPath, childNode).
    Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 2379 times.
    Similar Threads
    Drawing at nodes
    JTree not repainting
    How to display the borders in Panels
    How to detect FocusLost on JPanel
    Background image in jscrollpane
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 13:03:11.