java - Help with a Swing JFrame with 3 comboboxes and a vector variable -


i created swing jframe 3 comboboxes , vector variable populate them, comboboxes empty on execution of code. can tell me wrong.

public class notes extends jframe {      jframe jf;     jpanel jp = new jpanel();     vector<integer> v = new vector<integer>();     int i;     integer x;     dimension d = new dimension(40, 12);      notes() {          jf = new jframe("combobox demo");          (i = 1; <= 31; i++) {             x = new integer(i);             v.add(x);         }          jcombobox date = new jcombobox(v);         v.removeallelements();            (i = 1; <= 12; i++) {             x = new integer(i);             v.add(x);         }          jcombobox month = new jcombobox(v);         v.removeallelements();           (i = 2011; <= 2020; i++) {             x = new integer(i);             v.add(x);         }          jcombobox year = new jcombobox(v);         v.removeallelements();           date.setsize(d);         month.setsize(d);         year.setsize(d);          jp.setlayout(new flowlayout(flowlayout.right, 5, 5));         jp.add(date);         jp.add(month);         jp.add(year);          jf.add(jp, borderlayout.page_start);          jf.setsize(300, 300);         jf.setvisible(true);         jf.setdefaultcloseoperation(exit_on_close);      }      public static void main(string arg[]) {         new notes();     } } 

it's pretty obvious because removing elements of vector:

v.removeallelements(); //that's wrong 

when pass v jcombobox constructor, combobox doesn't copy each value references vector gave it. if remove elements vector, you'll see empty combo box.

if doing reuse v variable after each cicle substitute wrong lines above :

v = new vector<integer>(); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -