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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:36:33+00:00 2026-05-27T02:36:33+00:00

I have different objects which is used to store the data from DB in

  • 0

I have different objects which is used to store the data from DB in an ArrayList<T>. I got to show records of each in a Table. I use an AbstractTableModel for first object am working on. The AbstractTableModel class has an ArrayList<Relation> and an String[] of headers.

My question is : How do I create the same AbstractTableModel that can be used for all objects. I mean if working with Relation, I can have ArrayList<Relation>, if with Product, can have ArrayList<Product> ..etc. Writing different AbstrastTableModel for each is not a good idea according to me. The main problem comes with setValueAt, getValue, addRow….

    @Override
public void setValueAt(Object value, int row, int col) {
    Relation r = data.get(row);     // ArrayList<Relation> data
    switch (col) {
        case 0:
            r.setId(value.toString());
            break;
        case 1: r.setName(value.toString());
            break;
        case 2: r.setStartBalance((Double)value);
            break;
        case 3: r.setCurrentBalance((Double)value);
            break;
    }
}

Any good idea to work on this as a single model that works for all. And can also fire events from here for the table.

I know it is a bit complicated. But the structure is vast and creating new class of AbstractTableModel and JTable for each object is also not a good idea.

What do you suggest ?

  • 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-05-27T02:36:34+00:00Added an answer on May 27, 2026 at 2:36 am

    You can create an abstraction over your multiple data classes such that they expose methods like setValue(int columnNumber, Object Value) and similar getValue() method. Then you can write AbstractTableModel over this new abstraction. Afterwards creating required table model will just require changing the data class in constructor of your model.

    For instance you can have an interface:

    interface DBRow
    {
        public void setValue(int columnNumber, Object value);
        public Object getValue(int columnNumber);
    }
    

    Both Product and Relation classes should implement this and then your model can work on DBRow interface.

    You can also consider directly using resultset for populating tables:
    resultset-to-tablemodel

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

Sidebar

Related Questions

In my case I have 2D ArrayList full of objects that have data which
I have a project which exposes object model to use by different types of
I have an array of different type objects and I use a BinaryWriter to
I have an application that has many different types of objects that each persist
How would you tackle this problem: I have data in my data store. Each
We have used Zend_Log, which is configured in application.ini differently for different circumstances. We
I have a base class object array into which I have typecasted many different
I have one video object and 3 thumbnails which, when clicked, will play different
I have a bunch of different objects that are commonly edited in the same
I have an action method that takes in two different objects. I am posting

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.