wood burning stoves 2.0*
The moose likes Java in General and the fly likes Problems printing a Treemap 2nd run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problems printing a Treemap 2nd run" Watch "Problems printing a Treemap 2nd run" New topic
Author

Problems printing a Treemap 2nd run

Lucian Botezatul
Greenhorn

Joined: Jan 08, 2011
Posts: 20

After trying 3 days of try and error, i know that the first time when i asked for help, i put the wrong questions.

My second try: (sorry guys and ladys ...)

I have a TreeMap it does what it supposed to do perfectly, give out a list with Key, and Value.





Problem, i want print this list on a pop-up window and want to get the two tipes of bracket away

Now it looks like this:

Want looking like this, without brackets:


Number of the correct Answers

10 Fragen: Ben 10
9 Fragen: Ben 9
.........

Problem:





what i can put in the JTextArea so no barkets are there ?

FIRST try was:

make a iterator and put the value & key on a variable, then print them out:




Problem i get only the first a raw and not the whole list ...

1, [ Ben 1]


SECOND try was:

Put the keys and values in array and ... no good idea ... it prints the whole array of values then the keys like:

[[10, 9, 8 ... ] , [Ben 10], [Ben 9] ...]




So far i can see i get the names on the square brackets because they are stored on a array , the curly brackets because i put all the values on a map.
But still have no clue how to change that they are no barckets on my window.



Any ideas what i can change ??

Thanks!


Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
in your FirstTry (you don't list a method name), pass the JTextArea into the method. Each time you get a key and value within your loop that you want to add to the JTextArea, use JTextArea.append() to put that string in it.

It looks like your problem is that you have one string variable for the key and one for the value, and you replace each string's value each time through the loop, so that they never hold one value. If you wanted to put the entire JTextArea text into one string, you would need to add successive values to the result string each time through the loop. But if you let the iterator add values to the text area instead, then you don't need to do that.

rc
Lucian Botezatul
Greenhorn

Joined: Jan 08, 2011
Posts: 20

Thanks for the hint!

I put my two strings in a new String (umwandL_Va3) then try to add it to the JTextarea i get some issue:

---> Cannot make a static reference to the non-static method append(String) from the type JTextArea;

if i put the TextArea in the Loop the user must push "Ok" for each new line that is added to the window, thats why i have tried to print it all at one time.


Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
As I said, you need to pass your JTextArea into this routine; then the routine has a reference to your JTextArea and can add things to it. When I said you should use JTextArea.append(), I only meant to identify the routine, not that it should be called on the class. It needs to be called on your object.

(Incidentally, if you posted the whole routine instead of just the loop, it would be easier to help)

It might be something like this:


Now the JTextArea will have all the text it needs.

Incidentally, getValue() returns you an ArrayList; calling toString() on an ArrayList may not give you exactly what you want; this loop may have to have an inner loop that goes through that ArrayList, appending whatever you want from it into the JTextArea.

rc
Lucian Botezatul
Greenhorn

Joined: Jan 08, 2011
Posts: 20

THANKS Ralph!

I solved the arrayList problem :

Instead of using arrays:



i am now using Objects for each of my users:



Now i try it with your hint, it looks that it is all i need to solve my problem.
Lucian Botezatul
Greenhorn

Joined: Jan 08, 2011
Posts: 20

So guys, thats the code:



MANY THANKS, YOU MADE MY DAY
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems printing a Treemap 2nd run