·
The most
commonly used Swing component classes are:
JButton
|
JCheckBox
|
JComboBox
|
JLabel
|
JList
|
JRadioButton
|
JScrollPane
|
JTabbedPane
|
JTable
|
JTextField
|
JToggleButton
|
JTree
|
These
component classes are all lightweight, which means that they are all derived
from JComponent. The ButtonGroup class, which encapsulates a
mutually exclusive set of swing buttons, and ImageIcon, which encapsulates a graphics image. Both are defined by
Swing and packaged in javax.swing.
v JLabel
and ImageIcon:

JLabel(Icon
icon)
JLabel(String
str)
JLabel(String
str,Icon icon,int align)
Here, str and icon are
the text and icon used for the label. The align argument specifies the
horizontal alignment of the text and/or icon within the dimensions of the
label. It must be one of the following values: LEFT, RIGHT, CENTER, LEADING, or TRAILING. These constants are defined in the SwingConstants interface.

ImageIcon(String
filename)
It
obtains the image in the file named filename.

Icon
getIcon()
String
getText()

void
setIcon(Icon icon)
void
setText(String str)

import
java.awt.*;
import
javax.swing.*;
public
class MyLabel extends JApplet
{
public void init()
{
try
{
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
{
makeGUI();
}
});
} catch(Exception e){
System.out.println("Sorry some
error occured "+e);
}
}
private void makeGUI()
{
ImageIcon ic=new
ImageIcon("icon1.png");
JLabel l1=new JLabel("My
Icon",ic,JLabel.CENTER);
add(l1);
}
No comments:
Write comments