Class JsonTreePane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class JsonTreePane extends JPanel
The right half of the JsonSplitPane: a collapsible tree view of a parsed JSON structure.

Tree mapping

Gson's JsonElement hierarchy maps onto a DefaultMutableTreeNode tree as follows:

  • JsonObject — one child node per key, labelled "key". The value is recursively expanded as that child's subtree.
  • JsonArray — one child node per element, labelled [0], [1], etc. Each element is recursively expanded.
  • JsonPrimitive (string, number, boolean) and JsonNull — leaf nodes whose label includes both the key/index and the value, e.g. name: "Alice" or [2]: 42.

Expand policy

After building the model, only the root and its immediate children are expanded. Deeper nodes start collapsed so large documents do not flood the display. The user can expand/collapse nodes normally with mouse clicks or the arrow keys.

Path breadcrumb

A label at the bottom of the pane shows the full dot-notation JSON path of the currently selected node (e.g. parameters.curves[0].xData). It updates on every selection change.

Copy value

Right-clicking any leaf node shows a context menu with a "Copy value" item that puts the node's raw value string onto the system clipboard. Right-clicking a key/array node offers "Copy path" instead, which copies the full dot-notation path.

Search / filter

search(String) filters the tree to show only nodes whose label contains the query string (case-insensitive), along with their ancestor chain so the matching node is reachable. Clearing the query restores the full tree.

See Also:
  • Constructor Details

    • JsonTreePane

      public JsonTreePane()
      Create an empty JsonTreePane with a dark background, a path breadcrumb label at the bottom, and context-menu support.
  • Method Details

    • setRoot

      public void setRoot(com.google.gson.JsonElement root, String filename)
      Build and display a tree from the given Gson element.

      The root node is labelled with filename. After setting the new model, the root and its immediate children are expanded; all deeper nodes start collapsed.

      Must be called on the EDT.

      Parameters:
      root - the top-level JsonElement returned by Gson; must not be null
      filename - display label for the root node
    • clear

      public void clear()
      Clear the tree back to an empty state and reset the path label.

      Must be called on the EDT.

    • search

      public void search(String query)
      Filter the tree to show only nodes whose label contains query (case-insensitive), along with their ancestor chain.

      If query is null or blank the full unfiltered tree is restored. If no file is loaded this is a no-op.

      Must be called on the EDT.

      Parameters:
      query - the filter string; null or blank restores the full tree