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 7863845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:36:34+00:00 2026-06-02T23:36:34+00:00

I am working on a project that needs to show some data on a

  • 0

I am working on a project that needs to show some data on a jtable. I found many tutorials about jtables but few on how to customise a AbstractTableModel, the most parts are ready code.
Even in Oracle’s page I found this general jtable tutorial, but few information for
AbstractTableModel and how to make a customized model.Oracle Jtable Tutorial
I am new to programing so will be apriciate a tutorial for my level of skils.
Thank you in advanced.

  • 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-02T23:36:35+00:00Added an answer on June 2, 2026 at 11:36 pm

    The AbstractTableModel contains three methods that need to be overwritten. These are:

    public int getRowCount();
    public int getColumnCount();
    public Object getValueAt(int row, int column);
    

    The JTable uses these methods to find out how many fields (rows and columns) there are and to get the value (as type Object) of each field. When you overwrite these methods it is up to you which kind of data type you want to use. For example you can use a two dimensional Object array:

    Object[][] data;
    

    or an ArrayList of arrays:

    List<Object[]> data = new ArrayList<Object[]>();
    

    The fixed sized array might be easier to use but it is more difficult do dynamically add values. Of course you can also use Maps or other data structures. You just need to adjust your implementation of the three methods above to return the proper information from your data structure, such as how many rows your model currently contains, etc.

    There are also a couple more methods that can be overwritten but don’t have to. For example, if you want to have custom column names you must additionally overwrite the public String getColumnName(int col) method.

    For example like this:

    private static final String[] COLUMN_NAMES = {"User", "Password", "Age"};
    public String getColumnName(int col) {
        return COLUMN_NAMES[col];
    }
    

    Look at the Javadoc for AbstractTableModel to get an overview of other methods that can be overwritten.

    If you want to be able to change the Data in your TableModel then you need to overwrite the setValueAt method (if I am not mistaken):

    void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        //depending on your data structure add the aValue object to the specified
        //rowIndex and columnIndex position in your data object
        //notify the JTable object:
        fireTableCellUpdated(row, col);
    }
    

    Important: Whenever you add or remove a row, then the respective function in your TableModel implementation must call the respective fireTableRowsInserted (or deleted) function. Otherwise you will see strange visual effects happen to your JTable:

    public void addRow(Object[] dates) {
        data.add(dates);
        int row = data.indexOf(dates);
        for(int column = 0; column < dates.length; column++) {
            fireTableCellUpdated(row, column);
        }
        fireTableRowsInserted(row, row);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a php project that needs to store information about various
I'm currently working on an app using MVVM that needs to have some data
I'm working on a project that needs to have a list of weekdays. I
I am working on a project that needs rasterizing of drawings into image files.
I'm working on a project that needs a simple, lightweight event server (i.e. a
I'm working on a project that needs to have flexible authorization. What I mean
I'm working on a project that needs to check the time difference from a
I am currently working on a SharePoint project that needs to use the Lists
I currently started working on a maven web-app project that needs to be launched
On the project I'm working on, we have a file with svn:needs-lock that's frequently

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.