This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

customise string?  RSS feed

 
Lim Youjie
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for example.
System.out.print("Bold");

may i know how to customise the string. make bold or change its font type or size, etc.
 
Scott Selikoff
author
Bartender
Posts: 4093
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short, it usually depends on where your output is going. For example, if you are outputting to HTML, you just surround the text with <B></B> tags to make it bold, as well <font> tags for sizing and other options. If you are using Swing, there are a wide variety of libraries for formatting.

You can do some formatting of data types, such as truncating decimals to 2 digits using printf() the Java Util Formatter API.

For simple PrintWriters, such as System.out as you listed, I do not believe you can control the format other than what I have listed above.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using System.out.println() you cannot easily make bold or italic text because this is assumed to go a text-based console. If you need different fonts, you will probably need to use a GUI or some graphics library that supports fonts.

Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!