• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting JLabel text

 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I have a JLabel which show some Values like Max, Min and Avg values
i have added the JLabel text in the form of HTML which shows as below
Max : 10.4
Min :0.12
Avg : 123.34

So i have to format this string like
not able to format in this editor
This we can do using System.out.format("%10.2f",value);
But how can take that formated string to JLabel text. is any other way to achive this?

 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it we can use

String.format("%10.2f",1234.3f);

 
Campbell Ritchie
Sheriff
Pie
Posts: 49796
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must have copied those figures from a Government publication if the average is larger than the maximum

But, joking aside, why are you using floats?
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just i posted my test code..

And one more issue i am facing now.
the same text is taking more space in Chinese locale. because of the Font

How can i make the format string based on the Font?
So that it should not look odd in the different locale.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic