Java: Introduction to Components

Swing Components

You can draw things on the screen, but there are things that have already been made for you to put on the screen. These are called components. An example of a component is a label, button or scrollbar.

The Java Swing classes provide the tools that help you build a good graphical user interface. You've already used some of the drawing methods. In this section you will learn to use Swing components.

Some advantages of using these components are:

Defining your own components

The predefined Java components are adequate for all normal programming, with the one exception of drawing graphical output. In this case you want to define your own "component" that draws itself, which is easily done with a subclass of JPanel and overriding the default paintComponent method.

Examples

Some of the kinds of components that you will learn to use are JLabel, JTextField, and JButton.