Drawing

Why don't my calls to paint() and paintComponent() work properly?

If you want to draw a barcode onto a Graphics2D canvas then you should use the draw() method. The paintX() methods are used internally by Swing and should not be called by your code (even though they are public).

I have a Graphics object, but barbecue requires a Graphics2D. How do I get one?

It is safe to cast from a Graphics object directly to a Graphics2D.

I'm trying to print a barcode using a PrintJob from the default Toolkit, but I cannot cast the returned WPrintGraphicsWrapper to a Graphics2D. What should I do instead?

You should use the PrinterJob class instead. This will return a castable Graphics object.

When I try and generate a barcode on Solaris (or other unix variants inc. Linux) I get an InternalError about the X11 display not being available on 0:0. What is wrong?

There is a known issue with the Java runtime where a display is assumed to be present when accessing the graphics environment. More information is available at http://developer.java.sun.com/developer/bugParade/bugs/4281163.html, but the most common workaround is to run an X11 process purely to satisfy the needs of the JVM, even if the machine is headless.

When I try and generate a barcode I get a HeadlessException/UnsupportedOperationException. What is going wrong?

The machine generating the barcode is in Headless mode. The barcode servlet should automatically assume this mode, but you can force barbecue to do this at any time by calling EnvironmentFactory.setHeadlessMode() in your code. Alternatively, try explicitly setting the resolution on the barcode.