Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/08/2010, 10:07
41f4
 
Fecha de Ingreso: febrero-2009
Mensajes: 2
Antigüedad: 15 años, 2 meses
Puntos: 0
Respuesta: Alinear botones con BorderLayout Swing

Es por el tipo de Layout que estas usando prueba con FlowLayout o si quieres algo mas especifico usa GridBagLayout o setBounds (este no lo recomiendo)

Te dejo el código

Código Javascript:
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().setLayout(new FlowLayout());
  15.         frame.getContentPane().add(boton1);
  16.         frame.getContentPane().add(boton2);
  17.         frame.getContentPane().add(boton3);
  18.         frame.getContentPane().add(boton4);
  19.         frame.getContentPane().add(boton5);
  20.  
  21.         frame.addWindowListener(new java.awt.event.WindowAdapter(){
  22.            public void windowClosing(WindowEvent e){
  23.              System.exit(0);
  24.            }
  25.         }
  26.         );
  27.  
  28.         frame.pack();
  29.         frame.setSize(500,300);
  30.     }
  31. }