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.

My_JTable.java

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() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 400, 286);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
		
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(26, 46, 352, 131);
contentPane.add(scrollPane);
		
String[][] data = {{"Alex","Five","55","Male"},
	{"Ron","Six","65","Femal"}};
String[] column= {"Name","Class","Mark","Sex"};
		
jt1 = new JTable(data,column);
scrollPane.setViewportView(jt1);
}
Adding JTable to Swing window



Using JTable display records from MySQL database tables

swing MySQL & Java

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    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-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer