2

I'm currently working on a client-server project where the client sends a request to the server and the server runs a database statement based on the information from the client. As there's no static length for the output I add all the data to a ArrayList<String> and send it back to the client.

The data that the client requests has a certain hierarchy so that one could also display it using an XML file (however the output to a GUI is wanted here instead of file creation). There's several ways of displaying I came up with. One would be using a simple text area, however using this, I need to do applying the layout myself and the option of folding where I can expand and collapse certain items is not possible.

Another possibility of course would be using a simple JList, however I read on Stackoverflow that using a JList to display hierarchical things is way easier done using a JTree.

When I decided trying to implement JTree I also found the Genealogy.java file provided by Oracle in their documentation of JTree. As to be seen in the first examples of this documentation there is always a filestructure being displayed and hence also a filestructure kind of representation (using folder- and file-symbols) is shown. In contrast to this Genealogy.java only shows the names of the persons so I tried to adapt the implementation from Genealogy.java to my case however I'm completely clueless of how to do this as I don't even know where these symbols come from and where I could possibly disable them and also don't really get what some of the methods I need to implement do.

As I'm currently really clueless of how to possibly accomplish that I really need some detailed help (only telling me to come up with my own implementation of JTree or TreeNode doesn't really help me at this point). Is there any simpler way or is the need to implement any of the before mentioned interfaces inevitable and if so, how would it be done?


EDIT:

This is how it currently would be displayed (example taken from the Oracle documentation, showing folder- and file-symbols in front of the string):

JTree displaying folders and file symbols

And this is how I want it to be displayed (also from the documentation, this time only displaying a string as node):

JTree only displaying strings

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Samaranth
  • 385
  • 3
  • 16
  • What do you mean `it shows in a file structure`? Show how you want the data to be displayed within the tree. – DevilsHnd - 退職した Jul 19 '19 at 07:33
  • @DevilsHnd I hope my problem is easier to understand with the pictures provided now. – Samaranth Jul 19 '19 at 07:54
  • @AndrewThompson the documentation is linked. If you look in the 4th paragraph of the post there is a link to the Genealogy.java as well as to the Oracle documentation. – Samaranth Jul 19 '19 at 08:45
  • 1
    @AndrewThompson thanks for pointing that out. I indeed saw that chapter about customizing but when reading it appeared to me that it only is about the look and feel on the different OS's and about possibilities how to display the subfolder lines (angled, horizontal, none). That was exactly the part where I skipped the chapter hence I didn't read what would have been important for me. It works now, so if you want provide that as an answer so I can mark it as accepted answer. – Samaranth Jul 19 '19 at 09:31

1 Answers1

1

The answer almost certainly will be found via the (icon of the) TreeCellRenderer used for the tree nodes. See the File Browser GUI for tips. It shows how to set the icons in the FileTreeCellRenderer. Admittedly the point here is almost exactly opposite what it was there, but it still comes down to the same thing - the icons.

The section of the tutorial that covers it is How to Use Trees: Customizing a Tree's Display.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433