Java Reference
In-Depth Information
normal curve. Below the label showing an image is a
JLabel
that displays the name of
the image. For example, in Figure 12-17, this label displays the text
Normal Curve
.
The top and the bottom labels display a line of text, so they are manipulated using strings
as labels. The label showing an image is manipulated using images. For this program, we
include five JPEG images. The following statement creates the
JLabel
object
promptJL
with
Select an Image
as its label and sets the justification of the label to center:
private
JLabel promptJL =
new
JLabel("Select an Image",
SwingConstants.CENTER);
The following statements declare
displayPicJL
and
infoJL
to be reference variables of
the
JLabel
type:
private
JLabel displayPicJL;
private
JLabel infoJL;
We use
displayPicJL
to display the image and
infoJL
to display the name of the
image, as shown in Figure 12-17. The following paragraphs explain how to change the
text and image of these labels during program execution.
1
2
FIGURE 12-17
GUI using
JList
and
JLabel
We now discuss how to create the
JList
with five items. For the most part, creating a
JList
is similar to creating a
JComboBox
. To create a
JList
, we first declare a reference
variable as follows:
private
JList pictureJList;
Search WWH ::
Custom Search