开发者

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜