Java Reference
In-Depth Information
Frames, panels
and layouts
2
The basic element of any graphical operating system is a 'window'. In this chapter
we shall first learn how to create a window and how to display it on the screen.
Then we shall see how one can embed other graphical objects into the window and
how they can be arranged in different ways.
2.1
Frames
The main components of graphical applications are the so-called windows . These
are rectangular areas in which text, pictures or other information can be displayed.
Windows may also contain elements for user interaction, such as menus, buttons
or areas for text input. Most other graphical components discussed in this topic
cannot be displayed alone but have to be placed inside a window. The actual
appearance of a window depends on the operating system, especially the width
and type of the border around a window. The position and colour of buttons might
vary.
In Java, the term frame is used for what is generally called a 'window' and
we shall henceforth stick to that notation 1 .InSwing, frames are realized by the
class JFrame .Aframe is a rectangular area with a title bar on top. The title bar
also contains buttons for closing, maximizing or making an icon of the frame. As
mentioned above, the type and position of these buttons depend on the platform
(Windows, MacOS, Linux, Solaris, etc.). Below the title bar is an area into which
further graphical components can be embedded. This area is divided into two
parts: a space for a menu bar at the upper edge and the content pane below. The
content pane may have further graphical components embedded. If no menu bar is
added then the content pane is extended upwards. Usually there is a small border
around the frame to separate it from the background. The basic functions such as
resizing or moving the frame with the mouse are automatically supplied and do
!
not have to be implemented by the programmer. Figure 2.1 shows the structure
of a frame.
1
There is actually a component called 'window' in the Swing library. It is frameless, i.e. it
does not have a title bar, a border or additional buttons.
Search WWH ::




Custom Search