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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access