javaswingjtreetreecellrendererdefaulttreemodel

Compound JTree Node allowing events to pass through to objects underneath


Compound JTree Node allowing events to pass through to objects underneath

I went through the answer by @Jakub Zaverka ,which was pretty lucid.But what I could not understand is where is the code to create tree nodes (JTree ,food,sports,colors). Could someone explain how the nodes are created.

If I create a Node extending JPanel having a JButton and JLabel as fields ,can I set the node using the constructor of JTree which would be rendered and edited by the same custom renderer and editor.


Solution

  • The default JTree constructor "Returns a JTree with a sample model." To get the sample model, the constructor invokes the protected method getDefaultTreeModel(), which returns a sample model that is "Used primarily for beanbuilders to show something interesting." The values you see are contained in the source. A related example is seen here.