Can anyone help me get my output to display in my textArea? When I click the button, when the program is running, it wll display console output since I am using System.out.printf, but now I want it to show in my GUI. Any help would be appreciated. Thank you.

Recommended Answers

All 11 Replies

Replace all your System.out.printf statements with add statements for your text area, using String's format method to format just like in printf.

Is this what yu mean?

textArea.add( "%d) %.2f * %.2f = %.2f \n",i+1, Double.valueOf(priceList.get(i).toString()), Double.valueOf(quantityList.get(i).toString()), Double.valueOf(amountList.get(i).toString()));

Or will the formatting change because I need to use a different formatter? Thank you for the quick response. I am fairly new to this stuff.

Check out the format method in the String class (that's how printf does its formatting). Use that to get a String containing all your formatted values, then add that to the text area.

Should this work?

textArea.setText(String.format("%d) %.2f * %.2f = %.2f \n",i+1, Double.valueOf(priceList.get(i).toString()), Double.valueOf(quantityList.get(i).toString()), Double.valueOf(amountList.get(i).toString())));

That's the idea, yes. That way it's a simple find/replace on your existing printf statements, and there's no need to change the stuff that's specifying the formats or the data. (You may want to fine-tune the formats when you see the output, but that's up to you.)

Just try it with one or two printfs first and see how that goes.

Ok cool, I will give this a try. Thank you for your help.

Ok so now, my code compiles and runs with no errors, but when I click the Button, my textArea displays but with no output at all. I am a little confused now. I posted my whole code if you wouldn't mind seeing if you see something wrong?

I may not have time to read whole code tonight, so first try some simple debugging, eg
Try sending the output to both the text area and the console to see if that code is being executed and confirm what the output should be
Try adding some simple piece of fixed text to the text area, because if that doesn't work you have some other problem

Ok then. Thank you again. I was able to get the code to output to console again, but can not get anything to show up in my texArea. I will troubleshoot.

I do not understand why nothing is showing in my TextArea.

To add text to the text area use the append method, not setText (which replaces the previous text every time)

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.