I have a simple program with a potential complicated output (see below).

I am asked to make a simple for loop that displays results in GUI. Can I do this without with showmessagedialog instead of doing a JTextbox/label ect?

I need this:

sample gui output:

After year 1 $11000
After year 2 $12000
After year 3 $13000

Thanks a lot in advance for any guidance.

well sure, but why do you think that would be easier?
if you want to go to the next line within a String object, there's always the
"first line\nsecond line" you can use as a little bit of 'formatting'.

\n => n preceeded with the escape char \, forces a break in the line, this also works in a JOptionPane dialog.

well sure, but why do you think that would be easier?
if you want to go to the next line within a String object, there's always the
"first line\nsecond line" you can use as a little bit of 'formatting'.
\n => n preceeded with the escape char \, forces a break in the line, this also works in a JOptionPane dialog.

Thanks for reply. The professors result is 20 lines one after another on the showmessagedialog box. The \n works with one output. When I use a for loop it only executes one at a time and you have to press enter.

    for(periods = 1; periods<= periodLimit; ++periods) // for loop is most efficient 
    {
        balance = balance + balance * interest;

        JOptionPane.showMessageDialog(null,  "Your Investment at " + (100*interest) + "% = " +
        "\n\n" + "After year " + periods + "                " + "$" + df.format(balance));

Mark it as solved, please. :)

Mark it as solved, please. :)

first of all: stop adding useless posts to get your solved count up.
secondly: he may want to wait with this UNTIL HIS PROBLEM IS SOLVED.

*sigh*


@mcz2012

you can declare a String with empty startValue ( "");
and each iteration of your for loop:
myString += "This is the new line \n";

and then show that in your dialog. is that what you mean?

Whoa. There's a solved count? I'm going around telling people to mark their threads as solved so that they get added to the knowledge base and can help others, too. Seriously. :O

a lot of members will hate you If you go around posts telling them to mark their threads as solved while you have no proper contribution for the thread's solution, they'll think you just want to get your solved counts up like a parasite

:D I had no idea!
Well, from now on, I'll put it as my signature, so at least members on posts where I answer and contribute will mark their threads as solved. LOL :D

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.