Search code examples
javaswingnetbeansjtree

Oracle Java Tree Tutorial: Where and how to implement the tutorial code


I am now trying to learn java tree in java oracle tutorial here at creating a tree part. I have difficulties to implement the code inside my netbean jframe. where should i put the code. currently i put the code inside my public class jframe as shown below but return error.

enter image description here


Solution

  • private void createNodes(DefaultMutableTreeNode top) { //illegal start of expression

    Whoa, from the looks of your image, the method createNodes is inside the constructor, Hence //illegal start of expression. You'll want to take that out of the constructor and put it on the class level.

    Side Note

    • In Netbeans, make use of Shift + Alt + F to properly indent your code. You may notice errors you wouldn't see otherwise, like maybe this one :)

    • Providing us with actual text code is much more effective than providing a screen shot of your code.