import java.awt.FlowLayout;//especifica el orden de os componentes
import javax.swing.JFrame; //proporciona las caracteristicas de una ventana
import javax.swing.JLabel; //muestra texto o imagen
import javax.swing.SwingConstants; //constantes del swing
import javax.swing.Icon; //manipula imagenes, iconos
import javax.swing.ImageIcon; // carga imagenes
public class LabelFrame extends JFrame
{
private JLabel label1; //JLabel solo texto
private JLabel label2; //JLabel texto costruido con icono
private JLabel label3; //JLabel con texto adicional e icono
//------------agregar los objetos en JFrame
public LabelFrame()
{
super("Prueba JLabel");
setLayout(new FlowLayout()); //establece el marco
//JLabel constructor con argumentos string
label1=new JLabel("label con texto");
label1.setToolTipText("este es label1");
add(label1); //agrega label1 a JFrame
//constructor JLabel con String, icono y alineamiento
Icon bug=new ImageIcon(getClass().getResource("16.gif"));// especificar el nombre del gif
label2=new JLabel("label con texto e icono",bug,SwingConstants.LEFT);
add(label2);//agrega label2 al JFrame
label3=new JLabel();// JLabel constructor sin argumentos
label3.setText("label con icono y texto en el boton ");
label3.setIcon(bug);//agregar icono a JLabel
label3.setHorizontalTextPosition(SwingConstants.CENTER);
label3.setVerticalTextPosition(SwingConstants.BOTTOM);
label3.setToolTipText("este es linea 3");
add(label3);//agrega linea 3 al JLabel
}// fien del constructor LabelFrame
}// fin de la clase LabelFrame
nota se guarda con el nombre de LabelFrame.java
Publicar un comentario