Justify text

edited November 2014 in Android Mode


I'm finding some difficulty trying to have justified text in android mode. There is no align option for this, I found a nice method for Java mode here. The solution is to extend the PGrapahics object and override the text() and textLineImpl() functions.

Unfortunately, this is not working in android. Whenever I try to set the renderer to the extended one via sketchRenderer I get NullPointerException and the program closes. I'm doing it like this:

 public String sketchRenderer() {
    return "PGraphicsJava2DJustify"; 

I have tried extending all available PGraphics subclasses with no success. Any idea how to solve this?



  • Maybe instantiate a separate PGraphicsJava2DJustify exclusively for text(). :-??

  • Instantiating a separate PGraphicsJava2DJustify throws NPE every time I try to render through it. I tried with both new PGraphicsJava2DJustify() and createGraphics() (which does no accept a cast to PGraphicsJava2DJustify nor accepts "PGraphicsJava2DJustify" as the the third argument).

    Anyway, using this PGraphics subclass exclusively for text() would render the text to a different offscreen buffer that the one I am rendering all the other elements, wouldn't it?

    Thanks GoToLoop!

  • edited November 2014

    I've dabbled w/ customizing PGraphicsJava2D class and called it Layer in this thread: :ar!

    W/ that, I could add my own custom methods. I believe it's very similar to what PGraphicsJava2DJustify does.
    Perhaps you could adapt PGraphicsJava2DJustify code to work as a subclass of my Layer! 8-X

    Of course, try out that "JAVA2D Subclass" example from my link in Android mode and check out if it works there!

  • Thanks GoToLoop, I was on a tight deadline and skipped this feature, I'll let you know when I try your solution.

Sign In or Register to comment.