GraphicsBuilder: multiline text - No Fluff Just Stuff

GraphicsBuilder: multiline text

Posted by: Andres Almiray on February 28, 2008

One small issue that bothered me while playing with GraphicsBuilder's text node is that it is hard to draw a paragraph, in other words multiple lines of text. Of course you could call text many times but you have to be careful with keeping a record of the previous row's height and font. Applying a paint to the whole paragraph was not possible. Not anymore! text node is now capable of understanding multiline text, just make sure to separate each line with the '\n' char (yes it must be that char, no '\r\n' nor '\f' nonsense), here is a sample



Here is the code

Notice how the gradient is applied to all rows of text in a seamless way. text node also supports a new property: spacing, that will let you tweak how much space should be taken into consideration between each row of text. The next feature for this node would be to allow setting the horizontal alignment (and perhaps vertical too), right now you could say that text is always left-aligned with respect to x.

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »