Note that there are some explanatory texts on larger screens.

plurals
  1. POSame dataset, two different JTables
    text
    copied!<p>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).</p> <p>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.</p> <p>Now, a little example of my dataset structure as well as some dummy data:</p> <pre><code>class Student{ String name; Classroom classroom; boolean goodStudent} class Classroom{ Sting name; List&lt;String&gt; coursesTaught; List&lt;Student&gt; students;} public List&lt;Classroom&gt; classes; </code></pre> <p>Basically, my dataset will be the <code>classes</code> 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:</p> <pre><code>Classroom Name | Courses 4a | CS101, CS102, CS103 4b | BM101, CS102 4c | I101, CS4100 </code></pre> <p>So basically, for each Classroom, the list of courses.</p> <p>Table2 should instead show things like:</p> <pre><code>Student Name | Good? Mark Spencer | true Philippe Mann | true Tom Sayer | false </code></pre> <p>I should see ALL the students, from all classrooms.</p> <p>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:</p> <ul> <li>How will the Models get their data, once some change happens?</li> <li>Who should notify the models of this change?</li> <li>Is it enough to call "fireTableXXXEvent()" to trigger the view refresh?</li> </ul> <p>I hope I made myself clear enough... In any case, thank you very much! Bye</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload