First of all, thank you for taking the time to help me!
I am trying to print a couple of sentences on a message dialog with using string formatting.
When I use the string format and print it on the console, it prints with the proper format.
Like the image below:
However, when I try to print it on a Message Dialog, it prints with the wrong format, as show in the image below:
This is how I am printing this:
String result = new String();
for(int i = 0; i<stocks.length;i++){
result += stocks[i].toString() + "\n";
}
NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
// Prints Result on Console
System.out.println(result);
System.out.println("The total amount is: " + defaultFormat.format(BestStocksMA.getTotalCostMA()));
// Prints Result on Panel
JOptionPane.showMessageDialog(null, "Your companies and stocks are:\n" + result + "\nThe total amount is: " + defaultFormat.format(BestStocksMA.getTotalCostMA()));
And this is what I am using to format the String:
public String toString() {
String description;
description = String.format("%-25s", name) +
String.format("%-20s", defaultFormat.format(price)) +
String.format("%-20s", defaultFormat.format(calCostMA()));
return description;
}
How can I make it so the String prints in a 'pretty' and organized way on the Message Dialog just like it does when printed on the console?
Thank you so much!