0% found this document useful (0 votes)
107 views

JTable in Java Swing

The document discusses JTable in Java Swing. It describes how to create JTables using different constructors and how to add headers. It also provides a simple code example to demonstrate JTables.

Uploaded by

Kirti Phegade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

JTable in Java Swing

The document discusses JTable in Java Swing. It describes how to create JTables using different constructors and how to add headers. It also provides a simple code example to demonstrate JTables.

Uploaded by

Kirti Phegade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

3/28/2019 JTable in Java Swing

  Home Tutorials Core Java Advanced Java Programms Projects Downloads Contact

Java Programming

--Advertisement Here-- nusratsahib --Ad

Translate

JTable in Java Swing Adv


Advance Java
Home » Java » Advance Java » Java Swing II » JTable
Programming
Be the first of y
Core Java
Programming Swing A table is a component of the swing class that displays rows and columns of data. Tables are
Class Program Applet implemented by using the JTable class, which extends JCOmponents. The JTable component of swing
JFrame Java Database represents a two dimensional grid of objects. A JTable displays data in rows and column format. You
JPanel Event Listener Java
can edit data values in a table as well. The JTable class of swing represents swing tables. The JTable
Servlets Java Loops Ja
class extends the JCompoent class is stored in the javax.swing package. The syntax to create a table in
Branching Programming Section 1
File Handling GUI
Java Swing is:
Home
Programming UserInput
Program Exception Handling JTable <table_name>=new JTable(values[],column_names[]); Introduction
Graphics Programming Java Evoluti
MultiThreading Overview of
Constructor/Finalize The various constructors that swing provides to create a JTable are: Constants, V
Inheritance Java Images Array
Java Operato
Interface Java Beans JTable(): Creates an empty JTable.
M.S.Access Socket Branching S
Programming String Frame JTable(int row, int col): Creates a JTable with the size specified as arguments. The Looping Sta
JApplet JOptionPane Jumping arguments row and col are used to specify the number of rows and columns in the JTable.
in Loops Package RMI SQL Section 2
Vectors AWT Buttons AWT JTable(Object[][] row_data, Object[] col_names): Creates a JTable with the rowdata Classes, Obj
CheckBoxes AWT Choice
and the column names as specified in the arguments of the constructor. Inheritance
Controls AWT Labels AWT
Array, String
Radio Buttons AWT ScrollBars
JTable(TableModel d): Creates a JTable that is initialised with the TableModel passed as Java Interfac
AWT Scrolling Lists AWT
TextAreas AWT TextFields DSN
an argument to the constructor. Java Packag
InputDialogBoxes JButtons Java Applet
JCheckBox JComboBox
JTable(TableMode d, TableColumnModel c): Crates a JTable that is initialised with the
Java Graphic
JDesktopPane JEditorPane TableModel and TableColumnModel passed as an argument to the constructor.
JFileChooser JLabel JList
Advance Java P
JProgressBar JRadioButtons JTable(TableModel d, TableColumnModel c, ListSelectionModel s): Crates a JTable
JScrollBar JScrollPane JSlider that is initialised with the TableModel, TableColumnModel and ListSelectionModel Section 1
JSplitPane JTable JTextArea passed as an argument to the constructor. Java AWT
JTextField & JPasswordField
JTextPane JToolBar JTree Java JTable(Vector row_data, Vector column_names): Creates a JTable that displays the Java Event H
Programming Java Simple components of the vector arguments passed to the constructor. The argument, row_data is Java File Ha
Program Login Method Java MultiT
used to specify the data that is represented as rows in the JTable. The arguments,
Overloading Tables Update
column_name specifies the name of columns in the JTable. Java Swing-
Records
Java Swing-
Java Excepti
Useful Links
Table Header Section 2
NusratSahib.Com Java Socket
A table header is the top portion of each column in a table where the column title is displayed. In Swing, Java Databa
C Programming
the column header is represented by the class JTableHeader. The header of a table object can be retrieved Java RMI
C++ Programming
by calling the method getTableHeader(). There is another method called getDefaultTableHeader() that
C# Programming Java Servlet
returns the table header when no other header has been assigned. A different table header can be assigned
ASP Programming Java Beans
by using the class setTableHeader().

Simple Table Code Example


Visitors The following example creates a very simple table and adds it to an applet. The program uses the table
constructor that requires the number of rows and columns to be specified. The table is editable by default.

4 3 8 0 0 1

https://javaproglang.blogspot.com/2014/02/jtable-in-java-swing.html 1/4
3/28/2019 JTable in Java Swing
// Demonstrates how to create a simple table with the
// specified number of rows and columns.
Foll
// <applet code=JTableDemo1.class width=350 height=70>
// </applet>
Email address...
import javax.swing.*;

public class JTableDemo1 extends JApplet


{ Goog
public void init()
{
// 1. Create a table using the number of rows and
// columns and add it to the content pane.
JTable tbl = new JTable (4,5); // 4 rows & 5 columns

getContentPane().add(tbl);
}
}

C:\>jdk1.4\bin>javac JTableDemo1.java
C:\>jdk1.4\bin>appletviewer JTableDemo1.java

Output

Table Built with Arrays Code Example

The following example creates a Swing table in which the data to be displayed in a table has been stored in
array. The column array is simply in array of heading to be displayed in each column. The rows are
represented by an arrays because each row itself is an array of data items to be displayed. The table has
been positioned in an applet.

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

//<applet code="JTableDemo2.class" width=450 Height=250>


//</applet>

public class JTableDemo2 extends JApplet


{
// Create an array of name to be displayed in the table header.
String[] columnNames = {"Name", "Qualification", "No of years exp

// Create an array of row data(each row is an array) to be


// displayed in the rows of the table.
Object[][] rowData = {
{"Bintu", "M.C.A", new Integer (5)},
{"Laura", "B.Com", new Integer (4)},
{"Mirella", "B.E", new Integer (3)},
{"Pardeep", "B.Tech", new Integer (2)}
};

public void init()


{
// Create a table using the row and column data.
JTable table = new JTable (rowData, columnNames);

// Add the table column header and the table to the conte
getContentPane().add(table.getTableHeader(), BorderLayout
getContentPane().add(table);
}
}

https://javaproglang.blogspot.com/2014/02/jtable-in-java-swing.html 2/4
3/28/2019 JTable in Java Swing
C:\>jdk1.4\bin>javac JTableDemo2.java
C:\>jdk1.4\bin>java JTableDemo2

Output

Java Swing-II
JOptionPane Class Input Dialog Boxes JSliders
JProgressBars JTables JTabbedPane
JMenu JPopupMenu JToolBar
JFileChooser JScrollBar JScrollPane
JRootPane JTextPane JTree
JSplitPane JDesktopPane JEditorPane

PREVIOUS LYRICS NEXT LYRICS


JProgressBar in Java Swing JTabbedPane in Java Swing

Labels: Advance Java Programming, JApplet, JTable, Swing

Related Lyrics

JLabels - Displays an image Drops the Access/SQL table


JTextField &
and a string in a JLabel on - Java Database JRootPane in Java Swing
JPasswordField on JPanel
a JFrame Connectivity

Home » Java » Advance Home » Java » Advance Home » Java » Advance Home » Java » Advance
Java » » Swing ... Java » Java Dat ... Java » Java Swi ... Java » » Swing ...

No comments:

Post a Comment

https://javaproglang.blogspot.com/2014/02/jtable-in-java-swing.html 3/4
3/28/2019 JTable in Java Swing

Enter your comment...

Comment as: kirtiphegade14@ Sign out

Publish Preview Notify me

nusratsahib

Follow Advanced Java Programming on Facebook Popular Programs Follow Advanced Java Pro

Advanced Java Programming


Java Graphics Programming
Tweets by @AdvanceJava
Like Page 3.2K likes
Home » Java » Java Graphics
Programming Graphics is one of the most Java Programming
important features of Java. Java app... @AdvanceJava
Be the first of your friends to like this
Java Programming: Inser
M.S Access/SQL table us
Java Applet Programming Programming:
Home » Java » Java Applet Programming Applets javaproglang.blogspot.co
are small applications that are accessed from an internet ser...

Getting Input from the User in Java Applet


Applets work in graphical environment. Java Programming
Therefore applets treat input as text strings. We
@AdvanceJava
must first create an area of the screen in which ...
Java Programming: Using
javaproglang.blogspot.co
Java AWT (Abstract Window ToolKit)
Advanced Java Programming Home » Java » Advance Java » Java
about a year ago AWT (Abstract Window ToolKit) In Today's
World the Most im... Java Programming
Java Development Kit (JDK) 9 has finally been @AdvanceJava
released! Java Programming:
By Christina Mercer Sep 26, 2017| Display Numerical Values in Applet
javaproglang.blogspot.co
Java Development Kit (JDK) 9 is packed with new In applets, we can display numerical values by
first converting them into strings and then using …
features, including modularisation, ahead-of-time
the drawstring() method of Graphics class...
compilation, a read-eval-print loop and a memory-
saving improvement.

Powered by Java Programming © 2018

https://javaproglang.blogspot.com/2014/02/jtable-in-java-swing.html 4/4

You might also like