Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8824157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:32:21+00:00 2026-06-14T06:32:21+00:00

I am learning on how to use JTables in Swing. I have already figured

  • 0

I am learning on how to use JTables in Swing. I have already figured out to connect to a database and retrieve the resultset. I am also able to display the data by using the first option (see below).

a) I want to make sure I am understanding the idea of using/passing a TableModel versus directly passing the rows and columns is to have the ability to use built in methods that are available in AbstractTableModel; DefaultTableModel and ListTableModel classes.

b) What is a custom TableModel?

So far I have come across 4 ways:

  1. Pass columns and rows as objects directly to JTable constructor.

ex:

JTable tab = new JTable(Object [][] rows, Object[] cols);

2. Create a table model from a class that implements AbstractTableModel.

ex:

MyModel model = new MyModel(Object[][] obj1, String[] header);

//MyModel is a class that extends AbstractTableModel. 
//MyModel has an ArrayList<Object[]> to store obj1[]
//MyModel implements getRowCount(), getColumnCount() and 
getValueAt(int rowIndex, int columnIndex) and also getColumnName(int index)

JTable tab = new JTable(model);

3.Create a table model from a class that implements DefaultTableModel.

ex:

DefaultTableModel model = new DefaultTableModel(String data[][],String col[]);
(or)
DefaultTableModel model = DefaultTableModel(Vector data, Vector columnNames) 

JTable table = new JTable(model);

4.ListTableModel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:32:23+00:00Added an answer on June 14, 2026 at 6:32 am

    When you directly pass your data, the JTable will create a DefaultTableModel internally which you can get by calling table.getModel().

    Different TableModels have different features and you can implement your own by creating a class that implements TableModel or extends AbstractTableModel (or DefaultTableModel). The idea behind this is that you sometimes need more than just the raw table data.

    For example if you want to attach an Object to each row:
    You could write a TableModel that holds an object per row and provides methods like Object getObject(int rowIndex) and void setObject(int rowIndex, Object object).
    To do so you would hold an extra array or list inside your TableModel that contains the objects and is always of the same size as the amount of rows.

    Another reason could be that the tablemodel loads row data while you scroll or that you want display data from several data sources dynamically.

    A TableModel doesn’t necessarily have to hold the data, it just provides it to the JTable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning to use libgdx with universal-tween-engine and haven't been able to figure out
I am just learning to use Services, and am sort of stuck. I have
I am learning to use Subversion and am experimenting. I checked out a copy
I'm learning to use raw sockets, and im trying to prase out the tcp
I am learning to use mysql for rails apps, and I finally have been
I am learning to use sed and have a hypothetical requirement: bash$ cat states
I am learning to use Core Data. I have created a data model etc
I have enjoyed learning to use OpenGL under the context of games programming, and
I am learning to use Processing , and have modified one of the examples
I'm learning to use pointer to copy char array. I have the following code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.