Ajp PR8
Ajp PR8
8
Name: Pote Vighnesh Sandip Class: CO5I
Roll No: Batch: C
import javax.swing.*;
import java.awt.*;
public class PR8_1
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setVisible(true);
jf.setSize(400,400);
jf.setLayout(new FlowLayout());
String colnames[] = {"Sr No","Name","Contact No"};
Object data[][] = {
{1,"Suyash","9878456734"},
{2,"Shubham","8978675467"},
{3,"Vighnesh","8669483842"},
{4,"Riya","7972482121"},
{5,"Dipali","7879956457"}
};
JTable table1 = new JTable(data,colnames);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table1,v,h);
jf.add(jsp,BorderLayout.CENTER);
}
}
Output:
2. Write a program code to generate the following output.
Program:
package Practical8;
import javax.swing.*;
import java.awt.*;
Object data[][] = {
{101,"Amit",670000},
{102,"Jai",780000},
{101,"Sachin",700000}
};
JTable table1 = new JTable(data,colnames);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table1,v,h);
jf.add(jsp,BorderLayout.CENTER);
}
}
Output:
3. Write a Java program to create a table of Name of Student, Percentage and Grade of 10
students using JTable.
Program:
package Practical8;
import javax.swing.*;
import java.awt.*;
public class PR8_3
{
public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setVisible(true);
jf.setSize(400,400);
jf.setLayout(new FlowLayout());
String colnames[] = {"Name of Student","Percentage","Grade"};
Object data[][] = {
{"Suyash",78,'B'},
{"Shubham",74.78,'B'},
{"Vighnesh",81.89,'A'},
{"Riya",79.47,'B'},
{"Dipali",81.45,'A'},
{"Prathamesh",77.68,'B'},
{"Omkar",79.34,'B'},
{"Shrutika",82.20,'A'},
{"Krush",85.80,"A+"},
{"Akash",76.90,'B'}
};
JTable table1 = new JTable(data,colnames);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table1,v,h);
jf.add(jsp,BorderLayout.CENTER);
}
}
Output: