Question about write number in JLabel in Java?
How can I print number in any component like JL开发者_C百科abel with certain number of sapces
such as if I write :
double num = 123567;
label.setext(" number " + num + "is big") ; == > number 123567isbig
double num = 12;
label.setext(" number " + num + "is big") ; == > number 12 isbig
the number "num" is writen on 6 spaces in the both statment ..
How can I do that in Java ??
String formatNumber(int n) {
return String.format("%-12d", n);
}
label.setText(" number " + formatNumber(1234567) + "is big");
精彩评论