Tuesday , November 21 2017
Home / java / Java Swing JTable Example

Java Swing JTable Example

In this tutorials, we are going to create a simple JTable with Swing in Java. The Swing JTable is used to display data as regular two dimensional table of cells.

 Java Swing JTable :


package com.swing.examples;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class JTableDemo extends JFrame {
    JTable table;

    JTableDemo() {
        super("JTable Demo");
        String headers[] = { "Name", "Address", "Phone", "Experiance" };
        String data[][] = { { "Chandra", "Hyderabad", "4568569568", "true" },
                { "Srikanth", "Vijayawada", "8595652541", "true" },
                { "Rajesh", "Banglore", "8585656545", "false" },
                { "Charan", "Mumbai", "9858654852", "true" },
                { "Kumar", "Pune", "4568569568", "2" },
                { "Venu", "Chennai", "8451265923", "2" },
                { "Gopal", "Vizag", "7845956585", "2" } };

        // Creating JTable with table data and headers
        table = new JTable(data, headers);
        // Adding table to content pane
        getContentPane().add(new JScrollPane(table));
        setSize(500, 150);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new JTableDemo();
    }
}

Output :

Java Swing JTable

Happy Learning 🙂

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

How to add dynamic files to JTree

In the previous tutorial, we learn about a simple JTree. This tutorial is for adding …

Leave a Reply

Your email address will not be published. Required fields are marked *