Text Effects in Java

I haven’t seen many examples of using GlyphVector in Java2D to do text effects, like gradient fills or create outlines of text. So I tried.
Text Demo Screen shot
WebStart demo
Source code
Updated to fix issue with gradients.

There are a few odd things about GlyphVector. It contains methods to transform each glyph (a glyph could be character, part of a character, or multiple characters), but it seems that is incomplete. To transform each glyph, you’ll need to create a GeneralPath, obtain each glyph from the GlyphVector, transform it, and append it to the GeneralPath.

The gradient fills, beveling, and drop shadows could have been faked by using AlphaComposite and rendering multiple times, but the jiggle (Each character rotated slightly) and fatten needed the vector shapes instead of bitmap fakery.

The “fatten” is like Photoshop’s expand (or grow) selection. Expanding the section can help create a lot of effects and generally make text look better (most fonts are too thin for good looking titles). There does not seem to be an good way to approximate this in Java2D. The method implemented here is to use a Stroke to create an outline of the text and use Area to merge the text and it’s outline together. That is very slow. I’ve had a few other ideas for doing this, but I haven’t had time to try them.

I created this a few months ago and never posted. -I’m not sure the webstart demo and the source code still match.- This was a test-bed I created to try some effects that I later used in other places. I know the UI is not good, I needed something quick and usable. The are many other (better) uses for transforming glyphs like custom spacing between letters and creating type on a curve.

JTabbedPane Part 2.

Link to Part 1
Tab screen shot in action
The source code is at http://www.walkersoftware.net/downloads/tab.zip. (The source is only for the tabs, the application pictured above is not available.) It is basically to same code in this javaworld article, but modified to run on JVM after 1.3 (because is doesn’t rely the implementation of the windows look and feel. The included icon is from eclipse 3.X. I’ve also tweak the drawing a little and completely disabled the “Maximize” button. One of these days, I would like to write replacement of Tabbed Pane that is broken into separate components.