News:

Tekforums.net - The improved home of Tekforums! :D

Main Menu

Er...Sam?!

Started by M3ta7h3ad, March 28, 2006, 15:44:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

M3ta7h3ad

Just a quick query hopefully.

System.out.println(); - when shoved in a for loop does quite a nice job outputting an array/iterator full of stuff.

Is there anything that I can use to do it in a gui? like a scrollable gui element sort of like a textbox I guess.

How would I do it?

Christopher Monkey

off the top of my head, define your text area, then use

tJTextArea.append("Text");

where tJTextArea is the name of your text area

M3ta7h3ad

Would I need to make a string buffer for that and keep adding to it with \n between each line and then output it in one go?

or could just use

jTextArea.print(array[j]);

and it would make a lovely new line all of itself?

GroovyPigThing

cant you just do

for (all elements i of array) {

 textarea.append(array + "\n");

}

M3ta7h3ad

Quote from: GroovyPigThingcant you just do

for (all elements i of array) {

 textarea.append(array + "\n");

}

:o Dude if that works. I will promise never to crush you to death ever again :D

Christopher Monkey

Yea.....


while(array[i]!="\0")
{
   tJTextArea.append(array[i] + "\n");
   i++;
}


would do the same thing and would work for a flexible sized array

M3ta7h3ad

Ahh hell not so good.

"non static method append cannot be accessed from a static context."

M3ta7h3ad

Got around it :)

Used a StringBuilder object (WOO!!! so much faster than a stringbuffer, thank god for Java 1.5)

GroovyPigThing

if youre using java 1.5 you can even use a foreach loop

for (String str : array) {
    textarea.append(str + "\n");
}

M3ta7h3ad

Quote from: GroovyPigThingif youre using java 1.5 you can even use a foreach loop

for (String str : array) {
    textarea.append(str + "\n");
}

oooh... now thats a new thing I havent see before.

For each string in an array. May use that elsewhere in my program :)

How did you know this by the way?

Christopher Monkey

He programs in Java?!?!?!?

GroovyPigThing


M3ta7h3ad

Yeah, but ive been programming in Java for the last 3 years. :D lol.

Used to 1.4.2 but not really bothered finding out the latest functions in 1.5

cornet

Java only just got a foreach loop ... LOL

M3ta7h3ad

lol I have to say its quite a nifty function and cornet :P lol some of us have no choice over what languages we want to program :) Personally im learning Ruby on the side :)

http://www.tekforums.co.uk/posts/list/105/8.page#4355

WOOT.. All done.