June 2002
Beginner to intermediate
640 pages
14h 24m
English
JLabel is derived from JComponent, which is full of functionality such as the ability to set an icon or tooltip to a label. The following example illustrates some of the things you can do. Import the JLabel and JFrame classes.
>>> from javax.swing import JLabel, JFrame
Create a frame and a label; put the label in the frame's content pane.
>>> frame = JFrame(visible=1, title="JComponent/JLabel Demo")
>>> label = JLabel("JComponent/JLabel demo")
>>> frame.contentPane.add(label); frame.pack()
We'll use the label just created for the following exercises and examples.
The first JLabel we'll look at is toolTip, which provides help text about what a component does.
>>> label.toolTipText = "Tooltips are cool"
Read now
Unlock full access