0% found this document useful (0 votes)
46 views4 pages

Ajp PR8

Uploaded by

Vighnesh Pote
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views4 pages

Ajp PR8

Uploaded by

Vighnesh Pote
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No.

8
Name: Pote Vighnesh Sandip Class: CO5I
Roll No: Batch: C

Title: Write a program to create a JTable.

1. Develop a program to demonstrate the use of JTable.


Program:
package Practical8;

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.*;

public class PR8_2


{
public static void main(String[] args)
{
JFrame jf = new JFrame();
jf.setVisible(true);
jf.setSize(400,400);
String colnames[] = {"ID","Name","Salary"};

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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy