开发者

Question about write number in JLabel in Java?

开发者 https://www.devze.com 2023-01-06 14:41 出处:网络
How can I print number in any component like JL开发者_C百科abel with certain number of sapces such as

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

精彩评论

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