Creating a JTable Component

In this Java programming tutorial we are going to implement the simple JTable on the java swing frame with the help of some java methods.

Creating a JTable Component


Now you can easily create a JTable component. Here, the procedure for creating a JTable component is given with the brief description of JTable and it's components.

JTable: The JTabel component is more flexible Java Swing component that allows the user to store, show and edit the data in tabular format. It is a user-interface component that represents the data of  two-dimensional tabular format. The Java swing implements tables by using the JTable class and a subclass of JComponent

For learning complete JTable component you have to learn following parts:

  • JTable
  • Rendering
  • Table model
  • Observable event model
  • Tool tips

Rendering: In computer program, the rendering is a process that generates an image from a model. Model is a specification of three dimensional objects.

Table model: All tables contains of  its data from an object that implements the TableModel interface of java swing package. The TableModel interface uses the methods of JTable class that integrates a tabular data model.

Observable event model: The event model is a building block of graphical user interfaces (GUI). This is a user friendly and most common that is provided by the graphical frameworks. The observable is a system state property that determines by some sequence of physical operations.

Tool tips: The tool tips are most common graphical user interface that is used for displaying the message in small box given by the user appropriate message, when the mouse pointer or cursor goes on it, a message (description) appears without clicking it.

Description of program:

In this Java programming tutorial we are going to implement the simple JTable on the java swing frame with the help of some java methods. To create a JTable component, you need a java swing frame. The JTable based on the frame's panel contains multiple data in a tabular format such as rows and columns. 

Description of code:

JTable( Object data[][], Object col[]):
This is the constructor of JTable class that implements a JTable for displaying the values in tabular format like rows and columns. All rows must have the same length as column names. It takes two arguments: data and col.

data - It defines the all data that will have to create a JTable.
col - It specifies the name of each column of the JTable.

Here is the code of program:

import javax.swing.*;
import java.awt.*;

public class JTableComponent{
  public static void main(String[] args

  new JTableComponent();

  public JTableComponent(){
  JFrame frame = new JFrame("Creating 
JTable Component Example!"
  JPanel panel = new JPanel();
  String data[][] {{"vinod","BCA","A"},{"Raju","MCA","b"},

    String col[] {"Name","Course","Grade"};
  JTable table = new JTable(data,col);

Download this example.

Output of program:

Share on Google+Share on Google+

Creating a JTable Component

Posted on: April 14, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Creating a JTable Component   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
amitesh kumar
August 26, 2012
how to show data in jtable netbeans

pls give me source code jtable netbeans code
amitesh kumar
August 26, 2012
jtable creating source code

how to show data in jtable pls provide me source code netbeans
Ahmed Bedru
September 25, 2012
Creating and using JTable in Java programming

I need the correct and genuine response of the code for the Jtable from Java programming Expert
November 8, 2012
Column names

Why should we set the Column names that we don't use it here.
Siddharth Polisiti
January 21, 2014
The Missing Column Names

Good one but the column names are missing in GUI!