Francis
Francis

Reputation: 643

How to share information in Java between tabs in JTabbedPane

I have one tab that displays the list of users in a JTable that I have extracted from a database and another tab that displays JTextFields that want to edit the user details then save them to the database.

One of the unique feature of a user is a userID(Integer) that am able to get from the JTable depending on which row is selected.

Now I want use that userID and fill the JTextFields with data from the database to allow editing and hence save the new values below is the UI( can't post images)

Basically is how to share the Integer variable between the two tabs

Upvotes: 0

Views: 838

Answers (2)

mKorbel
mKorbel

Reputation: 109813

Upvotes: 3

Ashwinee K Jha
Ashwinee K Jha

Reputation: 9317

You need to have your own mechanism for communication between the tabs. For instance you can have a reference of second tab in first tab so that when row is selected in table you can call specific method in second component. If you want to decouple them you can add a listener interface which second component implements and adds itself as listener to first one and so on.

Upvotes: 1

Related Questions