How to add JTree dynamically to a created JScrollPane?

The MY Jtree component is created inside the function associated with the action. But I already created Jscrollpane in the constructor and added it to the JFrame.

Now in the function related to the action, I tried to add the dynamically created JTree to JScrollpane using

JScrollpaneobject.add(JtreeObject); JScrollpaneobject.revalidate(); 

But I can not see Jtree on Jscrollpane.

+4
source share
2 answers

direct version of the same:

  scroll.setViewportView(jTree) 
+7
source

scroll.getViewport (). Add (JTree)

+3
source

Source: https://habr.com/ru/post/1339967/


All Articles