java - Lists and GUI - dynamically -


i have questions working lists,

i write da ta composits blocks in gui, when dispose 1 of block need make block below block dispose dynamically change position..now if have 4 blocks, , i'm deleting second block, want make block 3 , 4 come on position 2 , 3 because when delete block 2 on position empty space..

    tabitem tbtmstudent = new tabitem(tabfolder_1, swt.none); tbtmstudent.settext("student");  scrolledcomposite scrolledcomposite_1 = new scrolledcomposite(tabfolder_1, swt.border | swt.h_scroll | swt.v_scroll); scrolledcomposite_1.addmousewheellistener(new mousewheellistener() {     public void mousescrolled(mouseevent e) {          scrolledcomposite.setfocus();     }    });  tbtmstudent.setcontrol(scrolledcomposite_1); scrolledcomposite_1.setexpandhorizontal(true); scrolledcomposite_1.setexpandvertical(true);   list<student> allstudentnodes = currentdata.getstudentnodes();  composite studentchild = new composite(scrolledcomposite_1, swt.none); studentchild.setlayout(new gridlayout());  for(student studentnode: allstudentnodes){      new studentnode(studentchild, swt.none, studentnode);      composite achivementschild = new composite(scrolledcomposite_1, swt.default);     achivementschild.setlayout(new gridlayout());      for(achivements achivementsnode: studentnode.getachivements()){         new achivementsnode(mscbcchild, swt.none, achivementsnode);     } } scrolledcomposite_1.setcontent(studentchild); scrolledcomposite_1.setminsize(studentchild.computesize(swt.default, swt.default)); 

if remove element list, elements later in list have position reduced one. try way:

allstudentnodes.remove(2); 

and check second , third element allstudentnodes.get(2) , allstudentnodes.get(3), respectively.

see description in docs:

e remove(int index)

removes element @ specified position in list (optional operation). shifts subsequent elements left (subtracts 1 indices). returns element removed list.

parameters: index - index of element removed returns: element @ specified position throws: unsupportedoperationexception - if remove operation not supported list indexoutofboundsexception - if index out of range (index < 0 || index >= size())

and

boolean remove(object o)

removes first occurrence of specified element list, if present (optional operation). if list not contain element, unchanged. more formally, removes element lowest index such (o==null ? get(i)==null : o.equals(get(i))) (if such element exists). returns true if list contained specified element (or equivalently, if list changed result of call).

specified by: remove in interface collection parameters: o - element removed list, if present returns: true if list contained specified element throws: classcastexception - if type of specified element incompatible list (optional) nullpointerexception - if specified element null , list not permit null elements (optional) unsupportedoperationexception - if remove operation not supported list

the second variance calls first one, searches element first. so, whenever call remove, shift subsequent elements left, wanted. (http://docs.oracle.com/javase/7/docs/api/java/util/list.html)


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -