Java Reference
In-Depth Information
Creating the BorderLayout with two int parameters adds spacing between the components
that it lays out. And finally, setting an EtchedBorder for the imagePanel adds a line with
an “etched” look around the image. (Borders are defined in the package javax.swing.
border —we have to add an import statement for this package.)
All the improvements discussed in the section have been implemented in the last version of this
application in the topic projects: imageviewer3-0 . In that version, we have also added a Save As
function to the file menu so that images can be saved back to disk.
And we have added one more filter, called Fish Eye , to give you some more ideas about what
you can do. Try it out. It works especially well on portraits.
Further extensions
Programming GUIs with Swing is a big subject area. Swing has many different types of com-
ponents and many different containers and layout managers. And each of these has many at-
tributes and methods.
Becoming familiar with the whole Swing library takes time, and is not something done in a few
weeks. Usually, as we work on GUIs, we continue to read about details that we did not know
before and become experts over time.
The example discussed in this chapter, even though it contains a lot of detail, is only a brief
introduction to GUI programming. We have discussed most of the important concepts, but
there is still a large amount of functionality to be discovered, most of which is beyond the
scope of this topic. There are various sources of information available to help you continue.
You frequently have to look up the API documentation for the Swing classes; it is not pos-
sible to work without it. There are also many GUI/Swing tutorials available, both in print and
on the web.
A very good starting point for this, as so often is the case, is the Java Tutorial, available publicly
on Oracle's web site. It contains a section titled Creating a GUI with JFC/Swing ( http:// ).
In this section, there are many interesting subsections. One of the most useful may be the sec-
tion entitled Using Swing Components and in it the subsection How To. . . It contains these en-
tries: How to Use Buttons, Check Boxes, and Radio Buttons ; How to Use Labels ; How to Make
Dialogs ; How to Use Panels ; and so on.
Similarly, the top-level section Laying Out Components within a Container also has a How
To... section that tells you about all available layout managers.
Exercise 11.51 Find the online Java Tutorial section Creating a GUI with JFC/Swing (the
sections are called trails on the web site). Bookmark it.
Exercise 11.52 What do CardLayout and GroupLayout have to offer that is different
from the layout managers we have discussed in this chapter?
Search WWH ::

Custom Search