Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
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"},
     {
"Ranjan","MBA","c"},{"Rinku","BCA","d"}};

      String col[] {"Name","Course","Grade"};
    JTable table = new JTable(data,col);
    panel.add(table,BorderLayout.CENTER);
    
frame.add(panel);
    frame.setSize(300,200);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

Output of program:

                         

» View all related tutorials
Related Tags: c com class orm ant form model io components sed color format component value byte int rgb show pixel for

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

3 comments so far (
post your own) View All Comments Latest 10 Comments:

Thanks for such a nice site with meaningful information.

Posted by skg on Thursday, 09.11.08 @ 14:37pm | #78671

I saw your JTable Example where u added JTable to a JPanel,but the header of the JTable is missing in output.I am facing same problem.Is there any solution.

Posted by Manish on Thursday, 08.7.08 @ 13:16pm | #71544

Hi,

I felt very happy by reading the JTable related web pages from your site.

Thank you.
Nagarajan. A.

Posted by Nagarajan on Thursday, 03.27.08 @ 03:49am | #54444

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.