Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/08/2010, 08:25
tazzwt
 
Fecha de Ingreso: marzo-2010
Mensajes: 432
Antigüedad: 14 años, 1 mes
Puntos: 11
Alinear botones con BorderLayout Swing

Hola porfavor.

Como puedo alinear y ordenar los botones en un JFrame usando Swing

Eh usado distintas propiedades del BorderLayout como CENTER, NORTH, SOUTH, WEST y EAST. Pero no queda igual como la imagen 2

Ahora ultimo estoy usando CENTER pero se agrupan todos los botones en un solo lado (imagen 1).

La idea es que queden como la imagen 2.

Imagen 1: El código me crea esto:
http://i30.tinypic.com/2yw8kxv.png

Imagen 2: Esto es lo que quiero hacer:
http://i25.tinypic.com/xfoqra.png

Código:

Código Java:
Ver original
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class test3 {
  6.     public static void main(String[] args) {
  7.         JFrame frame = new JFrame("Prueba");
  8.         JButton boton1 = new JButton("boton 1");
  9.         JButton boton2 = new JButton("boton 2");
  10.         JButton boton3 = new JButton("boton 3");
  11.         JButton boton4 = new JButton("boton 4");
  12.         JButton boton5 = new JButton("boton 5");
  13.                    
  14.         frame.getContentPane().add(boton1,BorderLayout.CENTER);
  15.         frame.getContentPane().add(boton2,BorderLayout.CENTER);
  16.         frame.getContentPane().add(boton3,BorderLayout.CENTER);
  17.         frame.getContentPane().add(boton4,BorderLayout.CENTER);
  18.         frame.getContentPane().add(boton5,BorderLayout.CENTER);
  19.  
  20.         frame.addWindowListener(new java.awt.event.WindowAdapter(){
  21.            public void windowClosing(WindowEvent e){
  22.              System.exit(0);
  23.            }
  24.         }
  25.         );
  26.  
  27.         frame.pack();
  28.         frame.setSize(400,300);
  29.         frame.setVisible(true);
  30.     }
  31. }