Swing JTable in JFrame

Using swing JFrame we can easily display any tabular data by using JTable.

Adding JTable

We will display one JTable by adding two rows of data with one header column. To display any column Header along with the data we must add JScrollPane and place the JTable inside it. If we don’t require the header then adding JScrollPane is not required.


Creating JFrame others..

Create the file by clicking icon below File or by pressing Ctrl and N .

Creating JFrame
Other .. > JFrame > JTable1>Finish
Go to Design Tab and add absolute Layout
Layout > Absolute 
Adding JScrollPane
Containers > JScrollPane 
Give one area to JScrollPane on your JPanel to keep the JTable inside it.

Go to Components and select JTable, Place the JTable inside the JScrollPane.

Adding data and header column.

Use the Source Tab.

We will create two String arrays to store column header and two rows of data.
public JTable1() {
setBounds(100, 100, 400, 286);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(26, 46, 352, 131);
String[][] data = {{"Alex","Five","55","Male"},
String[] column= {"Name","Class","Mark","Sex"};
jt1 = new JTable(data,column);
Adding JTable to Swing window

Using JTable display records from MySQL database tables

swing MySQL & Java


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer