JTree with form builder

后端 未结 2 1346
闹比i
闹比i 2021-01-19 06:08

I created a form with default NetBeans edito and put a jTree on it. It somehow then creates bunch of elements such as \"colors\", \"sports\", \"food\" in there.

相关标签:
2条回答
  • 2021-01-19 06:48

    Problem in next you create your JTree like this JTree tree = new JTree() (according to docs) it has sample nodes. Add next lines after you create your nodes(root,child1,child2) and all will be work:

    DefaultTreeModel model =(DefaultTreeModel) jTree1.getModel();
    model.setRoot(root);
    

    Also you needn't to call jTree1.removeAll(); it is used for other purposes.(docs)

    Read tutorial for JTree

    0 讨论(0)
  • 2021-01-19 07:03

    Initialize your JTree inside the custom GUI initializer createUIComponents() method.

    To create custom GUI initializer source code for a certain component, follow this general procedure:

    1. Select the desired component.

    2. In the Inspector, check the option Custom Create.

    3. In the text editor, locate the method createUIComponents(), and type the desired source code. The code in this method will not be removed on compilation.

    Full explanation: https://www.jetbrains.com/help/idea/creating-form-initialization-code.html

    0 讨论(0)
提交回复
热议问题