They know how to add a JTable to a JFrame


I want to add a JTable to a JFrame to pure code without the NetBeans Desing tool

asked by Isaac Barragan 31.10.2016 в 02:22

1 answer


The easiest way is by following these steps:

  • Create an Arrangement of type Object for the value shown in the header of columnas
  • Create an Arrangement 2D of type Object for the values to be displayed in the JTable
  • You create your JTable by passing the two Arrangements created previously per parameter to the constructor
  • You add it to JFrame u Other contenedor

    Object[] nombrecolumnas = {"Nombre", "Apellido", "Edad"};
    Object[][] datos ={{"Nombre1", "Apellido1", 22},{"Nombre2", "Apellido2", 4}};
    tabla = new JTable(datos,nombrecolumnas);
  • answered by 31.10.2016 / 02:50