user3432225
user3432225

Reputation: 11

JCombo Box does not show updated model, how to refresh the combobox

JCombo box doesnot show the updated values of arraylist, where in when i print the array it shows it is updated with new value added i have used DefaultComboBoxModel to add the array

Kindly help me how to fire the changed contents to UI

JComboBox comboBox_CHR = new JComboBox();
File CHRXml = new File("CHR.xml");
ArrayList<String> chrNo = xml.readChrNum(CHRXml);
DefaultComboBoxModel model=new DefaultComboBoxModel(chrNo.toArray());

public MainPage() 
{
  ArrayList<String> chrNo = xml.readChrNum(CHRXml);
  chrNo = xml.readChrNum(CHRXml);
  model=new DefaultComboBoxModel(chrNo.toArray());  
  System.out.println(chrNo);
  comboBox_CHR.setModel(model);
  comboBox_CHR.setModel(model);
  comboBox_CHR.setBackground(new Color(176, 196, 222));
  comboBox_CHR.setBounds(105, 50, 348, 30);
  panel_Chr.add(comboBox_CHR);
}

Upvotes: 0

Views: 50

Answers (1)

user3432225
user3432225

Reputation: 11

It worked finally when i did the updation on an EDT

addComponentListener(new ComponentAdapter() 
{ 
@Override 
public void componentShown(ComponentEvent arg0)
 { 
if(CHRXml.exists())
{ 
ArrayList<String> chrNo = xml.readChrNum(CHRXml);
 chrNo = xml.readChrNum(CHRXml); 
comboBox_CHR.setModel(new DefaultComboBoxModel(chrNo.toArray()));
} 
else 
JOptionPane.showMessageDialog(null,"CHR database file doesnot exists");
 } 
});

Upvotes: 1

Related Questions