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.
This section has not yet been updated to reflect features and conventions of the latest release, JDK 6.0.
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.
Describes how painting happens,
with special attention
to the framework provided by JComponent
.
Gives an overview of the coordinate system, including how borders affect it, and discusses theGraphics
andGraphics2D
classes.
Tells how to implement painting code
within a Swing component
using the paintComponent
method.
Summarizes this lesson and points to where you can find out more.
Describes some common problems related to painting, along with possible solutions to these problems.
Try these questions and exercises to test what you've learned in this lesson.