Trail: Creating a GUI with JFC/Swing
Lesson: Performing Custom Painting

Examples Index

Performing Custom Painting
You might not need to read this lesson at all. Many programs get by with no custom painting. If they display images, they do so using icons in standard Swing components such as labels and buttons. To display styled text, perhaps with embedded images and components, they use text components. To customize the edges of components, they use borders. To change the look of all components, they use a customizable look and feel, such as the GTK+ look and feel.

If you can't find a way to make a component look the way you want it to, then read on. This lesson introduces painting concepts, as they apply to Swing components, and then refers you elsewhere so you can write painting code that makes your custom components look great.

How Swing Components Are Displayed

Describes how painting happens, with special attention to the framework provided by JComponent.

Introduction to Painting Concepts

Gives an overview of the coordinate system, including how borders affect it, and discusses the Graphics and Graphics2D classes.

Implementing a Custom Component

Tells how to implement painting code within a Swing component using the paintComponent method.

Summary

Summarizes this lesson and points to where you can find out more.

Solving Common Painting Problems

Describes some common problems related to painting, along with possible solutions to these problems.

Questions and Exercises

Try these questions and exercises to test what you've learned in this lesson.

Note: You can get the old version of this lesson by downloading the Swing trail as of May, 2003.

The old version of this lesson featured API introduced in 1.0 and 1.1, including the Graphics and MediaTracker classes. We recommend that you use newer API such as the Java 2D Graphics and Image I/O APIs. The old version of this lesson also had a discussion of animating images. If you think the animation discussion should be updated and made available for easy browsing, please tell us.


Previous page: Previous Lesson
Next page: How Swing Components Are Displayed