You are here:   HomeJava ProgrammingSwingJava - JLabel and Image within JApplet
by Dinesh Thakur Category: Swing

A label is a simple control which is used to display text (non-editable) on the window. Since it does not possess any user interactive feature, it is considered as a passive control. A label is an object of

JLabel class.

Some of the constructors defined by JLabel class are as follows.

JLabel ()

JLabel(String string)

JLabel(String string, int align)

where,

string is the text used for the label

align specifies the horizontal alignment of the text contained in the label, and can have one of the following values: LEFT,RIGHT,CENTER,LEADING or TRAILING.

import java.awt.*;
import javax.swing.*;
public class JavaExampleLabelImageInJApplet extends JApplet
 {
   public void init()
    {
       Container Cntnr = getContentPane();
       JLabel Lbl = new JLabel("Label",new ImageIcon("Koala.jpg"),JLabel.CENTER);
       Lbl.setVerticalTextPosition(JLabel.BOTTOM);
       Lbl.setHorizontalTextPosition(JLabel.CENTER);
       Cntnr.add(Lbl);
  }
}
/*<APPLET CODE=JavaExampleLabelImageInJApplet.class WIDTH=510 HEIGHT=210></APPLET>*/

java - JLabel and Image within JApplet





Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article