'Change the items of JComboBox depending on File Chosen

I am using Jython to create a GUI. I include a button - Upload which when clicked opens up a FileChooser and depending on the File chosen, I want to create my JComboBox. When the file is changed/ another file is uploaded, the items of JComboBox should also change.

def upload(self,event):
                self.chooseFile = JFileChooser()
                filter = FileNameExtensionFilter("c files", ["c"])
                self.chooseFile.addChoosableFileFilter(filter)
                ret = self.chooseFile.showDialog(frame_2, "Choose file")
                if ret == JFileChooser.APPROVE_OPTION:
                        file_name = self.chooseFile.getSelectedFile().getName()
                        txt4.setText(file_name)
                        file = self.chooseFile.getSelectedFile()
                        global file_path
                        file_path = file.getCanonicalPath()
                        with open(file_path) as f:
                                first_line = f.readline()
                                self.list_columns = first_line.split("\t")
                                self.source = JComboBox(self.list_columns)
                                self.target = JComboBox(self.list_columns)
                                self.source.setBounds(200,240,200,100)
                                self.target.setBounds(600,240,200,100)

When the above code is made to run, the dropdown for JComboBox does not change, instead, it remains of the previous file. Can anybody help me on how to clear and update the items of JComboBox?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source