The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail Search
Feedback Form
Examples Index (1.4)

Trail: Creating a GUI with JFC/Swing

Lesson: 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 the Creating a GUI with JFC/Swing trail) in standard Swing components such as labels (in the Creating a GUI with JFC/Swing trail) and buttons (in the Creating a GUI with JFC/Swing trail). To display styled text, perhaps with embedded images and components, they use text components (in the Creating a GUI with JFC/Swing trail). To customize the edges of components, they use borders (in the Creating a GUI with JFC/Swing trail). To change the look of all components, they use a customizable look and feel (in the Creating a GUI with JFC/Swing trail), 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 (in the Creating a GUI with JFC/Swing trail)

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. (outside of the tutorial)

The old version of this lesson featured API introduced in 1.0 and 1.1, including the Graphics (in the API reference documentation) and MediaTracker (in the API reference documentation) classes. We recommend that you use newer API such as the Java 2D Graphics (in the Creating a GUI with JFC/Swing trail) and Image I/O (outside of the tutorial) 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 Lesson Contents Next Page Start of Tutorial > Start of Trail Search
Feedback Form
Examples Index (1.4)

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.