Creating and Attaching label1
Now that we’ve specified the window’s layout, we can begin creating and attaching GUI components to the window. Line 23 creates a JLabel object and passes "Label with text" to the constructor. The JLabel displays this text on the screen. Line 24 uses method setToolTipText (inherited by JLabel from JComponent) to specify the tool tip that’s displayed when the user positions the mouse cursor over the JLabel in the GUI. You can see a sample tool tip in the second screen capture of Fig. 12.7. When you execute this application, hover the mouse pointer over each JLabel to see its tool tip. Line 25 (Fig. 12.6) attaches label1 to the LabelFrame by passing label1 to the add method, which is inherited indirectly from class ...
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