Hello Friends,
Can someone please advise me on how to print an array inside of a GUI text field?
Thank you,
Jim
Here is some of my code.

        /**
       This private inorder method recursively 
       traverses a binary tree in inorder.
       @param btree The root of the tree to traverse.
      */

         private void inorder(AVLNode btree)
         {   
            int [ ] arr = new int[10];


            if (btree != null)
            {      

               inorder(btree.left);

               arr[k] = (btree.value); 

               inTextField.setText(arr[k]); //This gets me an error message.

               k++;    

               inorder(btree.right);                                                       
            }   
         } 

Recommended Answers

All 3 Replies

What's the error message?

1 arr is an array of ints, setText needs a String, so you need to convert your value
2 SetText replaces any existing text, so setting it in a loop will just show the last value; you need to append att the text together.

One way is to start with an empty String before the loop, then append all the values to that String inside the loop (you can append ints etc to a String, Java will convert automatically), then use it to setText after the loop.

inorder method everytime initialize with new array when call it from inside if loop.

Also i think,inside if loop it doesn't go to line 15 and so on.

so first check your code.
And also as james said: you have to convert int array into string and merge them then insert into textfield.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.