O'Reilly logo

Java™ How to Program, Seventh Edition by P. J. Deitel - Deitel & Associates, Inc., H. M. Deitel - Deitel & Associates, Inc.

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

9.8. (Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels

Programs often use labels when they need to display information or instructions to the user in a graphical user interface. Labels are a convenient way of identifying GUI components on the screen and keeping the user informed about the current state of the program. In Java, an object of class JLabel (from package javax.swing) can display a single line of text, an image or both. The example in Fig. 9.19 demonstrates several JLabel features.

Figure 9.19. JLabel with text and with images.
 1 // Fig 9.19: LabelDemo.java
 2 // Demonstrates the use of labels.
 3 import java.awt.BorderLayout;
 4 import javax.swing.ImageIcon;
 5 import javax.swing.JLabel;
 6 import javax.swing.JFrame; ...

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