Posts

Showing posts from July, 2014

Pretty Print Large Texts in JAVA.

Image
Admit it, you have always wanted to impress your companion fellows adding impressive banners into your logs, it will seriously degrade performance but will fire your 'cool factor' up to the stars. For example:  public static void main(String[] args) { System.out.println(PrettyPrinter.prettyPrint("Big Enormous Rooster",200,25)); } Program output when told to print "Big Enormous Rooster" Here is the code of the method to acomplish your 'become popular' task: /** * Prints a text in a beautiful and pretty way */ public static String prettyPrint(String msg, int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setFont(new Font("Trebuchet Ms", Font.PLAIN, height)); Graphics2D graphics = (Graphics2D) g; graphics.setRenderingHint(RenderingHints.KEY_TE