I have created two JFrames. First one contains a JComboBox which lists data taken from a Database and second JFrame adds data to the database which the the JComboBox in first JFrame lists. After adding data to the database through second JFrame i closed the second JFrame and checked the list in JComboBox in first JFrame but it does not show the updated list. I checked the database,there the data is being added. JComboBox only loads the updated data if i close the first JFrame and re-open it. I want to load the updated list in JComboBox without closing the JFrame(First one). Is there any way to do that?(May be something to reload the whole first Jframe).
Asked
Active
Viewed 81 times
1
-
some code showing how the frames and database are defined is probably needed, there are lots of different ways to achieve this and lots of ways it could go wrong depending on who has access to what. – Linus Nov 08 '15 at 14:43
-
See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Nov 08 '15 at 21:57
1 Answers
1
and second JFrame adds data to the database
You should NOT be using multiple JFrames. An application should only have a single frame. You should be using a JDialog
for child windows.
After adding data to the database through second JFrame i closed the second JFrame and checked the list in JComboBox in first JFrame but it does not show the updated list.
It is the responsibility of your child window to update the combo box. So when you click on the "Save" button of the dialog the ActionListener code needs to do two things:
- update the database with the new value
- update the combobox with the new value. So this means that when you create the JDialog you need to pass the combo box (or the ComboBoxModel) as a parameter to that class so you can update the combo box. Or, you need to return a value from the dialog so that when the dialog is closed you can update the combo box.

camickr
- 321,443
- 19
- 166
- 288