Rendering on Components

Any object derived from the Component class has a Graphics object that can be used to render graphics onto it. This means that the developer can render high impact graphics on all types of buttons, canvases, and check boxes. Basically, all the user interface objects have an accessible Graphics object that can be cast as a Graphics2D object and used by Java 2D.

Scaling to the Component's Size

So far, the examples have been deficient because they don't take the component size into account when drawing. It is obviously good programming practice to determine the Component's width and height and then scale the drawing accordingly. This can be done by using the Component's getSize() method. Scaling is used in the comprehensive ...

Get Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.