Featured Post

Friday, February 28, 2020

Swing programs using JTable

import javax.swing.*;
import java.awt.*;
public class JTabledemo extends JApplet
{
  public void init()  
  {
    try
    {
       SwingUtilities.invokeAndWait(new Runnable()
       {
        public void run()
        {
         makeGUI();
        }
        });
      }
     catch(Exception e)
     {
         System.out.println("Cant create becuase "+e);
     }
  }

private void makeGUI()
{
  //Intilize columns headings
  String[] colheads={"Name","roll no","group"};
  //Intilize data
  Object[][] data={{"kumar","121","MCA"},
                  {"nani","122","MCA"},
                  {"ashok","123","M.Tech"},
                  {"suresh","124","M.Tech"}};
      JTable jt=new JTable(data,colheads);
      add(jt);

     /*if table size is big then we use scrollpane to display table*/
     //JScrollPane jsp=new JScrollPane(jt);
     //add(jsp);

}
}

******************************************************************
<html>
<body>
<applet code="JTabledemo.class" width=200 height=300>
</applet>
</body>

</html>

*******************************************
Output:

No comments:

Post a Comment