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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:46:49+00:00 2026-05-27T20:46:49+00:00

I have some data I have to show through two JTables; the data is

  • 0

I have some data I have to show through two JTables; the data is the same, but each table will have to show it a little differently.
Also, I receive the data from an external connection (JMS in this case, but it doesn’t really matter, it could be a DB, or whatever).

Being that I am new to Swing, I am still a little confused about who should fire the events, who should listen to them and how to make so that for a modification to my dataset I will have both the tables to update.

Now, a little example of my dataset structure as well as some dummy data:

class Student{ String name; Classroom classroom; boolean goodStudent}
class Classroom{ Sting name; List<String> coursesTaught; List<Student> students;}

public List<Classroom> classes;

Basically, my dataset will be the classes field in a Controller class and the two JTables will have to show things in different ways.
Namely, Table1 will have to show something like:

Classroom Name | Courses
4a             | CS101, CS102, CS103
4b             | BM101, CS102
4c             | I101, CS4100

So basically, for each Classroom, the list of courses.

Table2 should instead show things like:

Student Name   | Good?
Mark Spencer   | true
Philippe Mann  | true
Tom Sayer      | false

I should see ALL the students, from all classrooms.

As you can see, the data is the same, but it is shown in different way.
What I would like to do is that, when my data changes, the tables will automatically update too.
For what I understood so far, I will have to subclass AbstractTableModel and create two different TableModels for the kind of data I want to show; what I don’t get is:

  • How will the Models get their data, once some change happens?
  • Who should notify the models of this change?
  • Is it enough to call “fireTableXXXEvent()” to trigger the view refresh?

I hope I made myself clear enough…
In any case, thank you very much!
Bye

  • 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-27T20:46:49+00:00Added an answer on May 27, 2026 at 8:46 pm

    You are right. You need 2 AbstractTableModels.
    Suppose you have the list List classesList classes as main data source. The first model row count will just return size() of the list. The second one will return sum of Students counts for each classroom. Column count for both models is 2. The inteeresting methods are getValueAt/setValueAt you have to find proper row. For the first list it’s easy just appropriate list item. For the second table model you have to calculate proper row and then iterate through the list of Students.
    Suppose something is changed in DB. You retrieve a new List. You can either find what’s changed, which rows/cols were inserted/removed/changed or just replase the data source list in both models and fire structure changed event to let JTable completely refresh content.
    Thre is no automatic update of models. You can write e.g. timer to check the changes each second/minute/hour or refresh on reopening the dialog/frame where the table is shown.

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

Sidebar

Related Questions

I have some data grouped in a table by a certain criteria, and for
I have some data. I want to go through that data and change cells
I have some data that won't printf.... echo works, but not printf There is
We have two web applications and each one is creating it's own data context
I have a table of data that contains about 260 rows. Each of these
I have one ListView which is showing me some data through an array (which
I have some data with messed-up accented characters. For example in the data we
I have some data of the form Key ID Link 1 MASTER 123 2
I have some data that I want to store somewhere in my Rails app
I have some data stored as ArrayList . And when I want to backup

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.