O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JComponent

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.

Working with Tooltips

The first JLabel we'll look at is toolTip, which provides help text about what a component does.

>>> label.toolTipText = "Tooltips are cool"

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required