Raymomd Masuku
Raymomd Masuku

Reputation: 27

bind data from jlist to appear on a jtable

I'm developing a JAVA swing application, developed using hibernate and mysql as a database.

I'm trying to bind data from a JList to appear on a JTable, when one of items in the list is clicked. For example i have different user types in my application, Supervisor, Manager, Administrator and others.

Each of the user type has users register under them. I want the application to show certain users when a certain item is clicked on the JList. Like when I click on the supervisor item then all registered supervisors must appear on the JTable. Don't know if I'm making sense, but you all allowed to reply and I will try to make you understand better. Thanks.

Upvotes: 0

Views: 789

Answers (1)

camickr
camickr

Reputation: 324197

Like when I click on the supervisor item then all registered supervisors must appear on the JTable.

One way is to populate the table with all the data and then filter the table when you select an item from the JList. Read the section from the Swing tutorial on Sorting and Filtering.

Otherwise you would need to dynamically query you database every time a JList item is selected.

In either case you will need to add a ListSelectionListener to your JList to invoke your processing. Read the section from the Swing tutorial on How to Use Lists for an example.

Upvotes: 1

Related Questions