title: How to resize the width of a JTree dynamically according to its width?
body: <p><a href="https://i.stack.imgur.com/6MS7m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6MS7m.png" alt="enter image description here" /></a></p>
  <p>I want my GUI behave as follows:
  When the trees expand or collapse the width of the trees and the parent-panel shall adapt accordingly.</p>
  <p>I tried using a Splitpane and</p>
  <pre><code>JPanel mytrees = ...
  JPanel rightside = ...
  JSplitpane sp = new JSPlitpane(JSplitPane.HORIZONTAL_SPLIT, true, mytrees, rightside);
  
  mytrees.setLayout(new GridLayout(1, 0));
  mytrees.add(leftTree);
  mytrees.add(rightTree);
  leftTree.addComponentListener(this);
  rightTree.addComponentListener(this);
  
  public void componentResized(ComponentEvent e) {
      if (e.getComponent() == leftTree || e.getComponent() == rightTree){
          mytrees.setPreferredSize(new Dimension(leftTree.getWidth()+righTree,getWidth(), 0));
      }
  }
  </code></pre>
  <p>At the moment this does not work. One reason is the layoutmanager. I think the gridlayout doesnt work because the columns all have same width and the righttree width update similarly to the lefttree width...
  <a href="https://docs.oracle.com/javase/tutorial/uiswing/layout/grid.html" rel="nofollow noreferrer">How to Use GridLayout(The Java...</a></p>