JTree - how to add nodes with a For-Loop?

前端 未结 2 384
你的背包
你的背包 2021-01-26 17:51

I have a simple JTree, that systematically adds nodes from relevant vars:

public void init()
{   
    final String section1 = \"JAVA\";

    final S         


        
相关标签:
2条回答
  • 2021-01-26 17:55

    You could put all of the values into an enum and iterate through that instead.

    http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

    0 讨论(0)
  • 2021-01-26 18:17

    The solution is very simple:

        for (int i=0; i<sections.length; i++) {
        selection = new DefaultMutableTreeNode(( sections[i]));
        title.insert(selection,0);
        }
    

    sections[i] needs double brackets

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