June 2002
Beginner to intermediate
640 pages
14h 24m
English
Labels are components for placing text in a container. From a user perspective, they're read-only, although their text can be changed programmatically. Let's have a short interactive session that demonstrates using javax.swing.JLabel.
Import the classes needed.
>>> from javax.swing import JLabel, JFrame
Create a frame to hold the label.
>>> frame = JFrame(visible=1, title="Label Demo")
Create the label, and add it to the frame; then pack the frame to make the label visible.
>>> label = JLabel("Hello World")#Create a label
>>> frame.contentPane.add(label) #add the label to the frame
>>> frame.pack()
For this next exercise we need to resize the window with the mouse so we can read all of the text in the frame caption (sometimes referred ...
Read now
Unlock full access