How to create simple table in Java Swing

A Table is used to display data in the form of rows and columns. It can allow editing of data which is optional. By default, the columns of a table can be resized.

 

It can be accomplished by dragging the mouse along with their boundaries. The columns can also be dragged to a new position. A table is an object of class JTable which is a subclass of JComponent.

 

 

import javax.swing.*;

class swingtable extends JApplet

{

      public static void main(String aa[])

          {

              JFrame jff=new JFrame("Table Demo");

               String dataa[][]={{"1","Pooja","90%"},

                           {"2","Geeta","88%"},

                           {"3","Geet","87%"},

                           {"4","Siman","82%"},

                           {"5","Prem","89%"},

                           {"6","Geeta","88%"},

                           {"7","Vrishti","78%"},

                           {"8","Akasi","91%"},

                           {"9","Allya","94%"},

            };

    String fields[]={"Roll No","Student Name","Percentage"};

     JTable jtt=new JTable(dataa,fields);

    JScrollPane panee=new JScrollPane(jtt);

     jff.add(panee);

     jff.setSize(500,500);

     jff.setVisible(true);

     }

  }

Output....

Simple Table in Java Swing