• 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
Marshal
Posts: 53141
124
  • 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.

 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!