June 2004
Intermediate to advanced
848 pages
21h 28m
English
JLabel is the simplest JComponent. It is a string, image, or both that appears onscreen. The contents can be left-, right-, or center-aligned according to an argument to the constructor. The default is left-aligned. JLabel is a cheap, fast way to get a picture or text on the screen.
Figure 21-2. How JLabel appears onscreen

// remember, we are only showing relevant statements from main() ImageIcon icon = new ImageIcon("star.jpg"); JLabel jl = new JLabel("You are a star", icon, JLabel.CENTER); frame.add( jl ); frame.pack(); // size the JFrame to fit its contents ...
Read now
Unlock full access