JTable

JTabel provides a very flexible capability for creating and displaying tables. It allows tables that can be constructed from arrays and vectors of objects.

Program

fdfdf

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.awt.Dimension;
import java.awt.FlowLayout;

class Frame extends JFrame {
  
    Frame()
    {
        setTitle("JTable");
        setLayout(new FlowLayout());
        setJTable();
        setSize(700,200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    private void setJTable()
    {
        String[] heading = {"Rank","Name","Country","Rating"};
        String[][] data = {{"1" ,"V.Kohli"        ,"INDIA"       ,"881"},
                           {"2" ,"A.B De villiers","SOUTH AFRICA","872"},
                           {"3" ,"G.J Bailey"     ,"AUSTRALIA"   ,"856"},
                           {"4" ,"H.M Amla"       ,"SOUTH AFRICA","840"},
                           {"5" ,"K.C Sangakkara" ,"SRI LANKA"   ,"833"},
                           {"6" ,"M.S Dhoni"      ,"INDIA"       ,"783"},
                           {"7" ,"I.J.L Trott"    ,"ENGLAND"     ,"725"},
                           {"8" ,"S Dhawan"       ,"INDIA"       ,"723"},
                           {"9" ,"T.M Dilshan"    ,"SRI LANKA"   ,"717"},
                           {"10","Misbah-ul-Haq"  ,"PAKISTAN"    ,"715"},};
        JTable jt = new JTable(data,heading);
        JScrollPane js = new JScrollPane(jt);
        js.setPreferredSize(new Dimension(400,150));
        add(js);
    } 
}

public class Javaapp {
   
    public static void main(String[] args) {
        
       Frame fr = new Frame();
    }
}

Leave a Comment