Create Software Components 

Using Java Level 2

 

 

Course Info

Scheme

Resources

Tutorials

Java Demos

Utilities

Links


 

   Swing

Introduction

This tutorial describes some basic Swing components.

Introduction

JComponent Class

Some Swing Components

 


Introduction

Many Swing components are available to us for developing applications and applets with graphical user interfaces.  We can have components such as JLabels and JToolTips that exist to present information to the user.  We can also have components such as JButtons, JTextFields, JCheckBoxes and JRadioButtons that exist to get input from the user.  

These component classes come with many useful methods of their own but other useful methods are inherited from parent classes.

 


JComponent Class

Almost all Swing components inherit from the JComponent class.  The diagram below shows the class inheritance structure.

Some useful methods of the JComponent class that are inherited by components such as JButton etc. are setToolTipText, setBorder and getBorder, setForegroundColor and getForegroundColor, setBackground and getBackground and setEnabled.  This is not a comprehensive list of the methods of the JComponent class, there are many more useful methods. 

Also, JComponent inherits from Container and Component which provide many useful methods. The Component class includes everything from providing layout hints to supporting painting and events. The Container class has support for adding components to the container and laying them out.

 


Some Swing Components

The Swing components we will consider in this tutorial are:-

  • JButton

an area that triggers an event when clicked

  • JLabel

an area where non-editable text can be displayed

  • JTextField

an area in which the user inputs data from the keyboard

  • JTextArea

an area for manipulating multiple lines of text.

  • JList

presents the user with a list of items displayed in column

  • JComboBox

provides a list of items from which the user can make a selection

  • JCheckBox

a state button that have on/off, true/false values

  • JRadioButton 

a group of buttons where only one button in the group can be true

There are other Swing components which will not be covered in this tutorial, such as JScrollPane, JProgressBar, JSlider amongst others.

 

 

  Site Home 

Java Home   

  Forum  

Course Info

Welcome

Overview

Assessment

Qualification

Scheme of Work

Assignments

Resources

Information

Blackboard

Learning Center

Web Materials

Reading

Java Demos

Utilities

Links

Lecture Materials

Tutorials & Notes

Exercises

Activities

Quizzes

 

Site Home

Top

Unit Home

ADR 2002