Creating and Attaching label3

Class JLabel provides methods to change a JLabel’s appearance after it’s been instantiated. Line 34 creates an empty JLabel with the no-argument constructor. Line 35 uses JLabel method setText to set the text displayed on the label. Method getText can be used to retrieve the JLabel’s current text. Line 36 uses JLabel method setIcon to specify the Icon to display. Method getIcon can be used to retrieve the current Icon displayed on a label. Lines 37–38 use JLabel methods setHorizontalTextPosition and setVerticalTextPosition to specify the text position in the label. In this case, the text will be centered horizontally and will appear at the bottom of the label. Thus, the Icon will appear above the text. The horizontal-position ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.