I wanna ask problem about list selection listener. In my application, I have 3 Jtable, lets say the first table is Student table, filled by student information, the second is semester table, filled by some semesters to the correspondent student (semester 1 to x), and the last table is result table, filled by result on the correspondent semester.
What i want to do is when I click a row in student table, semester table will update it's data, for example, it will filled by semester 1 to 6. Then, when i click a row in semester table, the result table will update it's data.
I can do it from student table to semester table with listselectionlistener and overriding valueChanged method. But how should i do for the same for semester table to result table? I'm getting stuck on this...
- i use database to retrieve all values to jtable -
edited : now I used SwingWorker, but i have another problem :
- When the UI is showing, the master table display a row (this is true)
- When i try to clicked that row, it dont clicked, i mean usually u will get a background in a selected row, but not with me (wrong->my problem)
- It also throw NullPointerException at my child table
- But when i wait for a while, it suddenly work again...
i've uploaded my sample code, and remove unrelated code here http://dl.dropbox.com/u/67181952/mycode.java
2nd code for error in child table http://dl.dropbox.com/u/67181952/spk.java
I hope i explained well, sorry for my bad english.
Thanks for any help :)
You can use
ListSelectionListener
added to selection models that you can get with getSelectionModel().Maintain the logic of presentation using table models. Once selection in
master
table changes update model/models ofdetails
tables accordingly. As a result of the data update, the model will notify its view (the table) about the changes. And view will refresh accordingly.Read more about models in How to Use Tables.
EDIT:
Since you load the data from database be sure to do it not from Event Dispatch Thread (EDT) to avoid performance issues. Look into SwingWorker to perform lengthy operations on a dedicated thread. Read more about Worker Threads and SwingWorker.
EDIT: following code upload
It seems that you misinterpreting
SwingWorker
specs.execute()
method is not blocking, it schedules worker execution and returns immediately. UI updates should be done inprocess()
ordone()
methods, which are invoked by the worker on EDT. Below is a revised version of one of the of functions from the code you posted: