Hello, i want to display a formatted string on dialog box. I formatted the string with using
String.format("%" + width + "s", str);
It wotks fine with System.out.println but not working on dialog box. Here is the code and screen shot.
//Here where i invoke the formatting method public String printAddedCourses(){ String str = ""; //String str = Arrays.toString(addedCourses); for(int i=0; addedCourses[i] != null; str += rightPad(addedCourses[i], 14); str += rightPad(Integer.toString(addedCredits[i]), 17); str += rightPad(addedCourseNames[i], 64); str += addedInstructors[i]; str += "\n"; } if( str.equals("")==true) return "None\n"; return str; }
//In here it displays the dialog message BUT NOT FORMATTED ! if( check == false){ JOptionPane.showMessageDialog(frame, "<HTML><FONT color=\"red\">Selected Courses:</FONT></HTML>" +"\n"+printAddedCourses() //IT HAVE TI PRINT HERE +"Total Credits: "+totalCredit +"\n\n<HTML><FONT color=\"red\">Conflicts:</FONT></HTML> \nNone" , "Analyze", JOptionPane.INFORMATION_MESSAGE); System.out.println(printAddedCourses()); } else if (check == true){ JOptionPane.showMessageDialog(frame, "<HTML><FONT color=\"red\">Selected Courses:" +"\n"+printAddedCourses() //IT HAVE TI PRINT HERE +"Total Credits: "+totalCredit +"\n\n<HTML><FONT color=\"red\">Conflicts:</FONT></HTML> \n"+printConflictedCourses() , "Analyze", JOptionPane.INFORMATION_MESSAGE); System.out.println(printAddedCourses()); }
This is from dialog box window, it is printing wrong !
ss.jpg
This is the Console show, here it is working correctly !
ss2.jpg
So where am i doing wrong ?