Currently I am having two panels with one JTree on left panel and another JTree on right panel. When I click a node of left JTree and click a move button then it will move to the right JTree. I am now able to make this. But now I am having a new requirement in the right panel there should be two options one is JTree and another is JTable. If JTree option is clicked then JTree should display the content or else if JTable is clicked then JTable should display the same content.
So kindly give me a solution for this. Is there a way for updating JTree and JTable with a same model. Or give me any other idea regarding this issue.
Originally posted by Melki Joe: Is there a way for updating JTree and JTable with a same model. Or give me any other idea regarding this issue.
You would get better results if you thought of reusing the same data instead of the model.
Image the typical windows explorer. Just like your UI, it displays a JTree on the left and a JTable on the right. However, in the table, since there are multiple columns, you can display more data. However, both the views are still referring to the same data, i.e. your file system.
So all you need to do is build a custom table model which can extract and return data from a given TreeModel.
Typically you will need to override the following methods in your custom model. 1)getColumnCount 2)getColumnName 3)getRowCount 4)getValueAt
Anyway I would be helpfull if I get a sample code regarding this.
I was expecting this
Come on.Its not that difficult. Look at the methods I mentioned. 1)getColumnCount. If this returns 3, the table will display 3 columns. I dont know your requirement. It is for you to decide how many columns need to be displayed. 2)getColumnName. Obviously the user would expect some name to the column. Depends on 1 above 3)getRowCount. Now this can be a bit tricky. In a tree you can collapse nodes. So what exactly is your requirement? When the user switches to table view, do you want to display only rows for visible tree nodes or even for nodes that are hidden? This method will have to return the row count accordingly. 4)getValueAt. This is the simplest one, but again depends on your requirement. What information do you need to display in the columns? Typically you have say a File object and you want to display the path in the 1st column, the size in the 2nd column and say last modified date in the 3rd column. The arguments for this method are the row count and the column count. So depending on those, you can return the relevant data.
Why dont you give it a try? You already have your table model. Just pass it to the table model you build, and pull out data for these methods from that model. In case you get stuck, post your relevant code. And dont forget to use the CODE tags
I am able to make designs as you said, but before going to that, when I click a JTree node and click move button then the the node should move to the other Jtree under the same parent node were the leaf node comes from. If there is no such parent node in the other JTree then it should create that node and want to move the leaf node under it. Give your idea on this.
Its all right, actually I am already having the code for moving nodes but I am having three parent nodes. How to identify each. Is there a way by giving path itself that it can identify the parent nodes and move to the corresponding place where it should go.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop