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

Practical No - 8

This document contains two Java programs that create JTables. The first program creates a JTable to display employee data including ID, name, and salary. It adds the JTable to a JScrollPane and adds that to a JFrame. The second program creates a JTable to display student data including name, percentage, and grade for 10 students. It also adds the JTable to a JScrollPane and adds that to a JApplet. Both programs demonstrate how to populate and display data in a JTable.

Uploaded by

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

Practical No - 8

This document contains two Java programs that create JTables. The first program creates a JTable to display employee data including ID, name, and salary. It adds the JTable to a JScrollPane and adds that to a JFrame. The second program creates a JTable to display student data including name, percentage, and grade for 10 students. It also adds the JTable to a JScrollPane and adds that to a JApplet. Both programs demonstrate how to populate and display data in a JTable.

Uploaded by

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

PRACTICAL 8

WRITE A PROGRAM TO CREATE A JTABLE.

import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
public class JTableDemo
{
public static void main(String[] args)
{
JFrame JFrameMain = new JFrame();
JFrameMain.setVisible(true);
JFrameMain.setSize(400,400);
String colHeads[] = {"ID","Name","Salary"}
Object data[][] = {
{101,"Amit",670000},
{102,"Jai",780000},
{101,"Sachin",700000} };
JTable JTableObj = new JTable(data,colHeads);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(JTableObj,v,h);
JFrameMain.add(jsp,BorderLayout.CENTER);
//JFrameMain.add(JTableObj);
}
}
2) Write a program to create a table of Name of Student, Percentage
and Grade of 10 students using JTable.
// Program to create a table of Name of Student, Percentage and Grade
of 10 Student
import java.awt.BorderLayout;
import javax.swing.JApplet;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.JScrollPane;
public class JTableStudents extends JApplet
{
public void init()
{
setVisible(true);
setSize(400,400);
//setLayout( new BorderLayout() );
String collumnHeading[] = {"Name","Percentage","Grade"};
Object data[][]={
{"A1",98,"A"},
{"A2",90,"C"},
{"A3",88,"A"},
{"A4",99,"A"},
{"A5",59,"A"},
{"A6",94,"D"},
{"A7",92,"A"},
{"A8",42,"C"},
{"A9",85,"A"},
{"A10",98,"B"}
};
JTable JTableObj = new JTable(data,collumnHeading);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(JTableObj,v,h);
add(jsp,BorderLayout.CENTER);
}
}
/*
<applet code="JTableStudents" height="400" width="400">
</applet>
*/

You might also like