JLabels

On Social Media

JLabels is a built-in Java Swing class that lets you display information on a JFrame. 

ConstructorsDescription
JLabel()Creates a JLabel instance with no image and with an empty string for the title.
JLabel(Icon image)Creates a JLabel instance with the specified image.
JLabel(Icon image, int horizontalAlignment)Creates a JLabel instance with the specified image and horizontal alignment.
JLabel(String text) Creates a JLabel instance with the specified text.
JLabel(String text, Icon icon, int horizontalAlignment)Creates a JLabel instance with the specified text, image, and horizontal alignment.
JLabel(String text, int horizontalAlignment)Creates a JLabel instance with the specified text and horizontal alignment.
MethodsDescription
String getText()Returns the text string that the label displays.
void setText(String text)Defines the single line of text this component will display.
Icon getIcon()Returns the graphic image (glyph, icon) that the label displays.
void setIcon(Icon icon)           Defines the icon this component will display.
int getVerticalTextPosition()Returns the vertical position of the label’s text, relative to its image.
void setVerticalTextPosition (int textPosition)Sets the vertical position of the label’s text, relative to its image.

ImageIcon

The ImageIcon class defines objects representing small fixed-size pictures that are used typically to decorate components.  This class implements the Icon interface.

ConstructorsDescription
ImageIcon()   Creates an uninitialized image icon.
ImageIcon(byte[] imageData)Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF or JPEG.
ImageIcon(byte[] imageData, String description)Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF or JPEG.
ImageIcon(Image image) Creates an ImageIcon from an image object.
ImageIcon(Image image, String description)Creates an ImageIcon from the image.
ImageIcon(String filename)          Creates an ImageIcon from the specified file.
ImageIcon(String filename, String description)Creates an ImageIcon from the specified file.
ImageIcon(URL location)Creates an ImageIcon from the specified URL.
ImageIcon(URL location, String description)Creates an ImageIcon from the specified URL.
MethodsDescription
Image getImage()Returns this icon’s Image.
void setImage(Image image)       Sets the image displayed by this icon.
int getIconHeight()Gets the height of the icon.
int getIconWidth()Gets the width of the icon.

Example


On Social Media

Leave a Reply

Your email address will not be published. Required fields are marked *