|
JLabel L1; Declares
the variable name of JLabels, JLabels can hold words or icons, used
for output only.
|
L1 = new JLabel("Hello World");
or
L1 = new JLabel( );
Creates the JLabel object. The JLabel is not visible
until it is added to the container. |
| container.add ( L1 );
Adds the
JLabel to the container (window). |
L1.setForeground(Color.red);
Sets the color of text
Choices of Color are:
Color.black, Color.white, Color.darkGray, Color.gray,
Color.lightGray, Color.blue, Color.cyan,Color.green, Color.magenta, Color.orange, Color.pink, Color.red, , Color.yellow |
L1.setToolTipText("Tool Tip Message ");
Enables
a Tip Box which to appear when the mouse is run over the JLabel
in the Container. |
L1.setIcon(new
ImageIcon("home.gif"));
Display a picture on the JLabel.. The gif or jpeg must be
stored in the same folder as the program code |
L1.setHorizontalTextPosition(SwingConstants.CENTER); Enables
the Text of the JLabel to be
justified horizontally LEFT, RIGHT or
CENTER of the Icon. |
L1.setVerticalTextPosition(SwingConstants.BOTTOM); Enables
the Text of the JLabel to be
justified vertically BOTTOM, TOP or
CENTER of the Icon |
To color the background of a JLabel, you must color the
background of the container or the
JPanel. container.setBackground(Color.green); |
L1.setText("this will go in
label"); - useful if you want to
change a JLabel in a
conditional
Prints
text in a JLabel - not used very often |
|
top
|