java - Unable to update JComboBox UI using a class method -


i facing problem populating list values in jcombobox. i've read integer values file using class method(which not subscribed actionevent), , modified combo box list contents. i'm unable see contents of ui updated .

why so? when use same code within action listener of button, can see combo box ui updated modified list values.

how can update combo box ui using simple method reads file , modifies combo box list values.

public class newjframe extends javax.swing.jframe{  public newjframe() { //constructor initialize form         initcomponents();         }  private void initcomponents() { butnext = new javax.swing.jbutton(); questionlist = new javax.swing.jcombobox();  …. …. //lines of code  questionlist.setmaximumrowcount(10);  org.jdesktop.beansbinding.binding binding =      org.jdesktop.beansbinding.bindings.createautobinding(org.jdesktop.beansbinding.autobinding.updatestrategy.read_write, questionlist, org.jdesktop.beansbinding.elproperty.create("${selecteditem}"), questionlist, org.jdesktop.beansbinding.beanproperty.create("selecteditem"));     bindinggroup.addbinding(binding);  questionlist.additemlistener(new java.awt.event.itemlistener() { public void itemstatechanged(java.awt.event.itemevent evt) {             questionlistitemstatechanged(evt);         }     }); questionlist.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) {             questionlistactionperformed(evt);         }     });  … … bindinggroup.bind();  pack(); setlocationrelativeto(null);  } //end of initcomponents    private void butnextactionperformed(java.awt.event.actionevent evt) {      // if i click next button on ui jcombobox populated vales read file         ….             …. // lines of code                                        queslistcontent.add(qnumber);         questionlist.additem(qnumber);   …. // lines of code    }   private  int defineexamstate() throws filenotfoundexception, ioexception{   // if i call function, on ui  jcombobox not populated vales read file,                                                                                                                                              //however values of list printed correctly when checked in submain() function string answerspath=newjframe.savedanswerpath; //file read  scanner input1 = new scanner(new file(answerspath));       while(input1.hasnextline())     {      string message = input1.nextline(); //user answers          switch (message) {             case "start":                  startcounter+=1;                 lastquestion=0;                  break;             case "end":                  queslistcontent.clear();                 questionlist.removeallitems();                 maxquestion=0;                 endcounter+=1;                  break;             default:                 record=message.split("q");                 lastquestion=integer.parseint(record[0]);                 if(!queslistcontent.contains(lastquestion)){                      queslistcontent.add(lastquestion);                 questionlist.additem(lastquestion);                  }                  break;           }         } }   protected  void submain() throws filenotfoundexception, ioexception, throwable {   //function  …  …. //lines of code   int size = questionlist.getitemcount();  for(int i=0;i<size;i++) {                 object element = questionlist.getitemat(i);                 system.out.println("element @ " + + " = " + element);  // able print content of combo box             } }   // variables declaration - not modify                        private javax.swing.jbutton butnext;   private javax.swing.jcombobox questionlist;  } // end of class definition 


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -