# Rotating label error

**URL:** <https://forum.inductiveautomation.com/t/rotating-label-error/36362>\
**Category:** Ignition\
**Created:** [July 4, 2020, 8:41pm UTC](https://forum.inductiveautomation.com/t/rotating-label-error/36362 "2020-07-04T20:41:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhettmotley](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@rhettmotley](https://forum.inductiveautomation.com/u/rhettmotley)\
**Post date:** [July 4, 2020, 8:41pm UTC](https://forum.inductiveautomation.com/t/rotating-label-error/36362/1 "2020-07-04T20:41:11Z")

</div>

I have been using this workaround for rotating a label using the paintable canvas for a while.

```auto
from java.awt import Color
from java.lang import Math
from java.awt import RenderingHints
from java.awt import GradientPaint
from java.awt.geom import Rectangle2D

g = event.graphics
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
fm = g.getFontMetrics()

#g.setColor(event.source.background)

#g.fillRect(0,0,event.width,event.height)

stringWidth = fm.stringWidth(event.source.text)
g.setColor(event.source.foreground)
g.rotate(-Math.PI/2)
g.drawString(event.source.text,-stringWidth,fm.getHeight())

```

now in 8.0.13  
getting an error…

Traceback (most recent call last):  
File “event:repaint”, line 17, in   
java.lang.NullPointerException  
java.lang.NullPointerException: java.lang.NullPointerException

caused by NullPointerException

Ignition v8.0.13 (b2020060815)  
Java: Azul Systems, Inc. 11.0.6

I do know in my application the custom property ‘text’ is empty at times.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 5, 2020, 2:05am UTC](https://forum.inductiveautomation.com/t/rotating-label-error/36362/2 "2020-07-05T02:05:14Z")

</div>

You have to code defensively in paint events, with heavy use of `try:`–`except:` or checks for null. Be aware that you can be called to paint for situations that have an incomplete `g`, like missing font or fontMetrics. Paint is likely to be called again immediately after `g` is complete, so it is best to simply draw nothing when encountering such errors.

Any other errors should be logged and handled defensively, drawing whatever is still possible, and never letting an exception “escape” from your paint method.
