I created a method to iterate through my array and collect all the values. I then appended the results to a String variable. When I append the variable to the TextArea, it shows all the values in one row. I want them to show up like a matrix with each row looking like this: Minutes = (column1 value) Earnings = (column2 value). This have been driving me nuts because I know how to format output if it was going to console using printf() but I can't figure out how to format the contents when it is all in a variable. My array stores double values because I'm working with decimals. Any suggestions would be highly appreciated. Here is my method code and my actionPerformed code:
public String printArray(){ for (int r=0; r < data.length; r++){ for (int c = 0; c < data[r].length; c++){ //System.out.printf("%8.2f%n", data[c]); prtData += Double.toString(data[r][c]); } } return prtData; } private void btn2ActionPerformed(java.awt.event.ActionEvent evt) { //Performing the required calculations for the report getMinTotal(); getEarnTotal(); getAvgWage(); performAnalysis(); prtData = printArray(); //declaring and initializing the StringBuilders StringBuilder sb1 = new StringBuilder(ast + ast + ast + newline); StringBuilder sb2 = new StringBuilder(ast + ast + ast + newline + newline); //Constructing the desired output for the JTextArea sb1.append(statement1 + newline); sb1.append(newline + prtData + newline); sb2.append(statement2 + newline + newline + statement3 + tab + totalMin); sb2.append(newline + statement4 + tab + dollar + totalEarn + newline); sb2.append(statement5 + tab + dollar + avgWage + newline + newline); sb2.append(statement6 + tab + dollar + minWage + newline + newline); sb2.append(statement7 + result + period); //converting the StringBuilders into the required String datatype sb1S = sb1.toString(); sb2S = sb2.toString(); //initializing the text area message variable and setting it to the tArea areaMessage = sb1S + newline + sb2S; tArea.setText(areaMessage); }