Ejemplo JPanel - GridLayout
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class InterfazEscuchadorMouse extends JFrame {
public JLabel etiqueta1;
public JLabel etiqueta2;
public JLabel etiqueta3;
public JLabel etiqueta4;
public JLabel etiqueta5;
public JButton boton1;
public InterfazEscuchadorMouse( )
{
setTitle( "Ejemplo de Escuchador Mouse" );
setLocationRelativeTo(null); //Ubica la ventana en el cento
setVisible(true); //Mostramos la ventana
setSize( 530, 530 ); //Definimos dimensiones Ancho=530, Alto=530
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );//Forzamos que se cierre la ventana cuando demos Cerrar
etiqueta1 = new JLabel("Etiqueta 1");
etiqueta1.setBounds(10, 160, 190, 20);
boton1 = new JButton();
boton1.setBounds(110, 75, 150, 75);
boton1.setText("Boton 1");
etiqueta2 = new JLabel("Etiqueta 2");
etiqueta3 = new JLabel("Etiqueta 3");
etiqueta4 = new JLabel("Etiqueta 4");
etiqueta5 = new JLabel("Etiqueta 5");
JPanel mipanel = new JPanel();
mipanel.setLayout(new GridLayout(2,3)); //Dos Filas por 3 Columnas
mipanel.add(boton1);
mipanel.add(etiqueta1);
mipanel.add(etiqueta2);
mipanel.add(etiqueta3);
mipanel.add(etiqueta4);
mipanel.add(etiqueta5);
//add(boton1);
//add(etiqueta1);
this.add(mipanel);
}
public static void main(String[] args) {
InterfazEscuchadorMouse e= new InterfazEscuchadorMouse();
}
}
Suscribirse a:
Enviar comentarios (Atom)
0 comentarios: