Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/06/2015, 17:09
inazense
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Problema: no muestra panel con botones al ejecutar

Te falta añadir el método pack() y setVisible(true). Añadí eso y ya me mostraba los botones, luego borras la línea 18 que te sobrescribía el gridlayout por un flow y descomentas la anterior línea.
También quité el initComponents(), porque en mi Eclipse me daba error.

Te copio el código tal cual.

Código Java:
Ver original
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4. public class EjemploGrid extends javax.swing.JFrame {
  5.     JPanel panelGrid;
  6.     JButton boton7, boton8, boton9, boton10, boton11,
  7.             boton12, boton13, boton14, boton15;
  8.     int contComponentes;
  9.  
  10.     public EjemploGrid() {
  11.      
  12.         this.setTitle("Ejemplo GridLayout");
  13.        
  14.         /*se crea el panel con gridlayout
  15.         este layout manager será establecido con tres filas  y tres columnas*/
  16.         panelGrid = new JPanel((new GridLayout(3,3)));  
  17.         panelGrid.setBorder(BorderFactory.createTitledBorder("GridLayout"));
  18.        
  19.         boton7 = new JButton("Botón7");
  20.         boton8 = new JButton("Botón8");
  21.         boton9 = new JButton("Botón9");
  22.         boton10 = new JButton("Botón10");
  23.         boton11 = new JButton("Botón11");
  24.         boton12 = new JButton("Botón12");
  25.         boton13 = new JButton("Botón13");
  26.         boton14 = new JButton("Botón14");
  27.         boton15 = new JButton("Botón15");
  28.        
  29.         panelGrid.add(boton7);
  30.         panelGrid.add(boton8);
  31.         panelGrid.add(boton9);
  32.         panelGrid.add(boton10);
  33.         panelGrid.add(boton11);
  34.         panelGrid.add(boton12);
  35.         panelGrid.add(boton13);
  36.         panelGrid.add(boton14);
  37.         panelGrid.add(boton15);
  38.        
  39.         this.getContentPane().add(panelGrid);
  40.         this.pack();
  41.         this.setVisible(true);
  42.     }
  43. //...
  44. }