Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/06/2009, 17:49
knzo25
 
Fecha de Ingreso: enero-2008
Mensajes: 46
Antigüedad: 16 años, 3 meses
Puntos: 0
Problema alineacion button

bueno mi problema es que uso frame.setLayout(new GridLayout(3, 2));
de modo que todo me queda dentro de eso
pero un ultimo boton me gustaria que estuviese centrado en la aplicacion
no centrado dentro de un espacio de la izquierda, como es que me esta quedando

dejo el codigo para ver si alguien me puede ayudar

Código:
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

   
 public class Main{  
    public static void main(String[] args){  
       
   JFrame frame = new JFrame("eA Server Control");
    JFrame.setDefaultLookAndFeelDecorated(true);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("eA Server Control");
    frame.setLayout(new GridLayout(3, 2));
    JLabel label1 = new JLabel("Host:", SwingConstants.RIGHT);
    JLabel label2 = new JLabel("User Name:", SwingConstants.RIGHT);
    JLabel label3 = new JLabel("Password:", SwingConstants.RIGHT);
    JTextField HostField = new JTextField(20);
    JTextField userNameField = new JTextField(20);
    JPasswordField passwordField = new JPasswordField();
    frame.add(label1);
    frame.add(HostField);
    frame.add(label2);
    frame.add(userNameField);
    frame.add(label3);
    frame.add(passwordField);
    label3.setHorizontalAlignment(JLabel.CENTER);
    label3.setVerticalAlignment(JLabel.CENTER);
    label2.setHorizontalAlignment(JLabel.CENTER);
    label2.setVerticalAlignment(JLabel.CENTER);
    label1.setHorizontalAlignment(JLabel.CENTER);
    label1.setVerticalAlignment(JLabel.CENTER);
    JButton button = new JButton("Connect");
    frame.add(button);
    frame.setSize(280, 120);
    frame.setVisible(true);
    }  
}
muchas gracias!!!