Tuesday, October 5, 2010

Textures as custom backgrounds

Just another short post about custom backgrounds. 
In my last post i forgot to mention that you could also use textures as backgrounds for your gauges.
Because the background has to be of type java.awt.Paint, it could also be a java.awt.TexturePaint.

With the right textures at your hand you could do things like this...


Here is the code that you need to achieve things like that...


// Create a gauge
final Radial4 RADIAL = new Radial4();

// Definition of the image file you'll use
final String IMAGE_NAME = "YOUR_IMAGE_FILE_NAME";

// Load the image file to a buffered image
final BufferedImage IMAGE = ImageIO.read(IMAGE_NAME));

// Create the texture paint from your image
final TexturePaint TEXTURE = new TexturePaint(IMAGE, RADIAL.getBounds2D());

// Set the texturepaint as background of your gauge
RADIAL.setCustomBackground(TEXTURE);

// Activate custom backgrounds for your gauge
RADIAL.setBackgroundColorFromTheme(false); 



So now it's up to you...

No comments:

Post a Comment