- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create DefaultTableModel which is an implementation of TableModel
Let us create DefaultTableModel −
DefaultTableModel tableModel = new DefaultTableModel();
Now, set the model to JTable −
JTable table = new JTable(tableModel);
Add a column −
tableModel.addColumn("Languages");
Now, we will add rows to our table −
tableModel.insertRow(0, new Object[] { "CSS" }); tableModel.insertRow(0, new Object[] { "HTML5" });
The following is an example to create DefaultTableModel −
Example
package my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo { public static void main(String[] argv) throws Exception { DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel); tableModel.addColumn("Languages"); tableModel.insertRow(0, new Object[] { "CSS" }); tableModel.insertRow(0, new Object[] { "HTML5" }); tableModel.insertRow(0, new Object[] { "JavaScript" }); tableModel.insertRow(0, new Object[] { "jQuery" }); tableModel.insertRow(0, new Object[] { "AngularJS" }); tableModel.insertRow(tableModel.getRowCount(), new Object[] { "ExpressJS" }); JFrame f = new JFrame(); f.setSize(550, 350); f.add(new JScrollPane(table)); f.setVisible(true); } }
Output
- Related Articles
- Java Program to create DefaultTableModel from two dimensional array
- Which is the fastest implementation of Python
- What is factors which affect the implementation of programming language?
- How to add some rows to a table through DefaultTableModel in Java
- How to retrieve the value from a table cell with TableModel in Java?
- What is the implicit implementation of the interface and when to use implicit implementation of the interface in C#?
- What is RPC Implementation?
- What is Implementation of connection less services?
- What is Implementation of LR Parsing Tables?
- What is Implementation of Syntax Directed Translators?
- What is the Microarchitectural implementation of branch processing?
- What is the implementation of a Lexical Analyzer?
- What is Implementation of Three Address Code Statements?
- What is Implementation of Simple Stack Allocation Scheme
- How to create an instance of an anonymous interface in Kotlin?

Advertisements