Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/03/2016, 10:48
jolut11
 
Fecha de Ingreso: marzo-2016
Mensajes: 19
Antigüedad: 8 años, 1 mes
Puntos: 0
Problema con GridBagLayout

buenas gente, estoy tratando de hacer un frame con un titulo en la cabecera centrado, una tabla en el centro y un par de botones abajo, este es el codigo que tengo:

import javax.swing.*;
import java.awt.*;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;


public class GridBagLayout {
static void mostrarGUI(){
JFrame ventana= new JFrame ("Creado con GridBagLayout");
String[][] filas= new String[2][2];
filas[0][0]="1";
filas[0][1]="2";
filas[1][0]="3";
filas[1][1]="4";

String[] columnas= new String[2];
columnas[0]= "Columna 1";
columnas[1]= "columna 2";

DefaultTableModel dtm= new DefaultTableModel(filas,columnas);

JTable tabla= new JTable(dtm);
JButton b1= new JButton ("Boton 1");
JButton b2= new JButton ("Boton 2");
JLabel titulo= new JLabel ("Tabla de array");

GridBagLayout gridbag= new GridBagLayout();
GridBagConstraints gbc= new GridBagConstraints();

ventana.setVisible(true);
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CL OSE);
ventana.setLayout(gridbag);

gbc.fill= GridBagConstraits.HORIZONTAL;
gbc.weightx=0.5;
gbc.gridx=0;
gbc.gridy=3;
gbc.gridwidth=3;
titulo.setHorizontalAligment(JLabel.CENTER);
ventana.add (titulo, gbc);


}
public static void main(String[] args){
mostrarGUI();
}
}

pero al tratar de compilar mi ide (BlueJ) me dice que el metodo setLayout (ventana.setLayout(gridbag);) no es usable...

Me gustaria saber que sucede y agradecería su ayuda, de antemano muchas gracias.