0

Currently, I am writing a java program that will try to scan a computer and present the memory component as a JTree like this Tree and work flow. The scan happens in two phases. In the first phase it will scan for Linux Device and insert the resulting Linux Device into the tree. In the second phase, the scan is looking for the UEFI device and insert them into the tree. And hence the structure of Linux Device on top and UEFI device at the bottom appear on the GUI (Java Swing).

After that, I export the information to a JSON file that contain the device name (ie. MD name) and their corresponding type Linux or UEFI. However, after I import the JSON file, I found out that proper order Linux device on the top and UEFI at the bottom is completely mess up.

I do some study on the JSON format and find out that it is unorder. Also, the lead engineer has required every export and import of the program would need to follow JSON so there is no way to choose something other than JSON.

What would be the appropriate engineer approach to keep the order of the item the same. The same as before import like this.

How to fix the problem of JTree nodes messing up after importing from JSON file?

5
  • 2
    If you want the json nodes to be ordered then you have a number of choices. Structure grouped elements together, this way when you read them back, you can choose how to display them. For elements in the groups, assign a sortable identify to each element, so you can ensure the sort order after you've parsed them back Commented Mar 8, 2022 at 8:04
  • The question in your latest edit was good. Thank you. I moved it into the body of the question. Still waiting to see that minimal reproducible example though. Having said that, I think the solution can be found via the advice of @MadProgrammer. How'd you go with that approach? Commented Mar 8, 2022 at 10:49
  • Thank you, but unfortunately I am working with an undocumented legacy code base and such change are quite aggressive. Commented Mar 8, 2022 at 14:11
  • "Thank you" Thank who? Tip: Add @MadProgrammer (or whoever, the @ is important) to notify the person of a new comment. Commented Mar 8, 2022 at 16:54
  • Oh I mean I would like to thank @MadProgrammer for his solution. Commented Mar 9, 2022 at 1:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.