java - Unable to scroll messages in J2me, I am using lwuit library -


i working last couple of month on j2me chat app. stuck in messages last 1 month. have added screen shot of message screen in comment.

my application scenario described below.

i have form named conservationform border layout. in main form have added further 2 container 1 msgpane boxlayout , other inputpane flowlayout. msgpane contains messages both receiver , sender. each complete message appended in msgpane in form of container named mycontainer. mycontainer contains text , images in form of labels have appended in mycontainer.

i have tried possible options efforts wasted , nothing achieved. in advance assistance.

my skills level in j2me , in lwuit beginner. seeking experts in j2me , lwuit.

i pasting code of conversation message below.

public void /*@shah displayable */  getguiconversation(string msgtext) {     final form conservationform = new form(currentroster.jid.getnickname());     boolean cananswer = currentconversation.cananswer();     conservationform.setscrollable(false);     //conservationform.repaint(); commented on 26-05-15     conservationform.setlayout(new borderlayout());     conservationform.setunselectedstyle(mainformstyling());     conservationform.settitlestyle(formheaderstyle());     conservationform.setmenustyle(formfooterstyle());     image icon, emoticonicon, attachmenticon;      button emoticonbtn, attachmentbtn;      int strlen = (int) (display.getinstance().getdisplaywidth()/16);      final container emoticonpanel = new container(new flowlayout());      final container msgpane = new container(new boxlayout(boxlayout.y_axis));      container inputpane = new container(new flowlayout());      style inputpaneustyle = new style();      style inputpanesstyle = new style();      inputpaneustyle.setmargin(0,0,0,0);      inputpaneustyle.setbgcolor(util.guiclass.buttonbgcolor);      inputpaneustyle.setfgcolor(util.guiclass.buttonbgcolor);      inputpanesstyle.setmargin(0,0,2,2);      inputpanesstyle.setbgcolor(util.guiclass.buttonbgcolor);      inputpanesstyle.setfgcolor(util.guiclass.buttonbgcolor);      inputpane.setunselectedstyle(inputpaneustyle);      inputpane.setselectedstyle(inputpanesstyle);      inputpane.setpreferredh(60);      try {          currentconversation.messages= datas.getmessage(currentconversation.name);      } catch (recordstoreexception ex) {      }      try {          icon = image.createimage("/res/smile.png").scaled(14, 14);          attachmenticon = image.createimage("/res/attach-icon.png").scaled(14, 14);  }catch(java.io.ioexception e){          icon = attachmenticon = null;      }      emoticonbtn = new button(icon);      attachmentbtn = new button(attachmenticon);      attachmentbtn.addactionlistener(new actionlistener() {          public void actionperformed(actionevent ae) {              showfiles();          }      });      vector msgs = currentconversation.messages;      message msg;      container mycontainer = null;      emotions em = new emotions();      (int i=0; i<msgs.size(); i++) {          msg = (message) msgs.elementat(i);          string msgstring="";          if(msg.from.equals(currentconversation.name)){              mycontainer = new container(new flowlayout());              style mycontainerustyle = new style();              style mycontainersstyle = new style();              mycontainerustyle.setbgcolor(0x75b0d2);              mycontainerustyle.setfgcolor(0x75b0d2);              mycontainerustyle.setpadding(1, 1, 1, 1);              mycontainerustyle.setmargin(5,5, 40, 5);              mycontainerustyle.setborder(border.createroundborder(12, 5, 0x75b0d2));              mycontainersstyle.setbgcolor(0x007bc1);              mycontainersstyle.setfgcolor(0x007bc1);              mycontainersstyle.setpadding(1, 1, 1, 1);              mycontainersstyle.setmargin(5,5, 40, 5);              mycontainersstyle.setbgtransparency(150);              mycontainersstyle.setborder(border.createroundborder(12, 5, 0x75b0d2));              mycontainer.setunselectedstyle(mycontainerustyle);              mycontainer.setselectedstyle(mycontainersstyle);              msgstring =  msg.gettext().trim();              float count = msgstring.length();              count = (count/strlen);              int pheight = (int)(30*math.ceil(count));              mycontainer.setpreferredh(pheight);              int pwidth = (int)((3/4)*display.getinstance().getdisplaywidth());              mycontainer.setpreferredw(pwidth);               string substr;              int index = -1;              (int j = 0; j < emotions.emoticonkeys.length; j++) {                  index = msgstring.indexof(emotions.emoticonkeys[j]);                  if(index>-1)                     break;              }              if(index>-1){                  int k = 0;                  string emotiid = "";                  while(index>-1){                      int currentindex = -1;                      (int j = 0; j < emotions.emoticonkeys.length; j++) {                          index = msgstring.indexof(emotions.emoticonkeys[j]);                          if(index>-1){                              if(currentindex<0){                                  currentindex = index;                              }                              if(index<=currentindex){                                  currentindex = index;                           emotiid = emotions.emoticonkeys[j];                              }                          }                      }                       substr = msgstring.substring(0, currentindex);                      msgstring = msgstring.substring(currentindex+emotiid.length());                      label lb;                      label emoticonlabel = new label("");                      try {                         emoticonicon = image.createimage((string) util.emotions.emoticonlist.get(emotiid)).scaled(14, 14);                         emoticonlabel = new label(emoticonicon);                       } catch (ioexception ex) {                      }                      emoticonlabel.getstyle().setmargin(0, 0, 0, 0);                      emoticonlabel.getstyle().setbgcolor(0x75b0d2);                      if(substr.length()>emotiid.length()){                         int strlength = substr.length();                         while(strlength>0){                              if(substr.length()>strlen){                                 lb=   new label(substr.substring(0, strlen));                                 substr = substr.substring(strlen);                                 strlength = substr.length();                             }else {                                 lb=   new label(substr.substring(0));                                 strlength = 0;                             }                             lb.getstyle().setbgcolor(0x75b0d2);                             lb.getstyle().setmargin(0, 0, 0, 0);                             mycontainer.addcomponent(lb);                         }                     }                      mycontainer.addcomponent(emoticonlabel);                      if(msgstring.length()!= 0){                          (int j = 0; j < emotions.emoticonkeys.length; j++) {                              try{                                  index = msgstring.indexof(emotions.emoticonkeys[j]);                              }catch (exception ex){                              }                              if(index>-1){                                 break;                             }                          }                         if(index<0 && msgstring.length()>(emotiid.length()-1)){                             int strlength = msgstring.length();                              while(strlength>0){                                   if(msgstring.length()>strlen){                                     lb=   new label(msgstring.substring(0, strlen));                                     substr = msgstring.substring(strlen);                                     strlength = msgstring.length();                                 }else {                                     lb=   new label(msgstring.substring(0));                                     strlength = 0;                                 }                                  lb.getstyle().setmargin(0, 0, 0, 0);                                  lb.getstyle().setbgcolor(0x75b0d2);                                  mycontainer.addcomponent(lb);                              }                          }                      }else {                          index = -1;                      }                  }               }else {                  int strlength = msgstring.length();                  while(strlength>-1){                      label  lb;                      if(msgstring.length()>strlen){                          lb=   new label(msgstring.substring(0, strlen));                          msgstring = msgstring.substring(strlen);                          strlength = msgstring.length();                      }else {                          lb=   new label(msgstring.substring(0));                          strlength = -1;                      }                      lb.getstyle().setmargin(0, 0, 0, 0);                      lb.getstyle().setbgcolor(0x75b0d2);                      mycontainer.addcomponent(lb);                  }              }              msgpane.addcomponent(mycontainer);              msgpane.setnextfocusdown(mycontainer);              msgpane.setnextfocusup(mycontainer);           }else{              mycontainer = new container(new flowlayout());              style mycontainerustyle = new style();              style mycontainersstyle = new style();              mycontainerustyle.setbgcolor(0x6d96ad);              mycontainerustyle.setfgcolor(0x6d96ad);              mycontainerustyle.setpadding(1, 1, 1, 1);              mycontainerustyle.setmargin(5,5, 5, 40);              mycontainerustyle.setborder(border.createroundborder(12, 5, 0x6d96ad));              mycontainersstyle.setbgcolor(0x6d96ad);              mycontainersstyle.setfgcolor(0x6d96ad);              mycontainersstyle.setpadding(1, 1, 1, 1);              mycontainersstyle.setmargin(5,5, 5, 40);              mycontainersstyle.setbgtransparency(150);              mycontainersstyle.setborder(border.createroundborder(12, 5, 0x6d96ad));              mycontainer.setunselectedstyle(mycontainerustyle);              mycontainer.setselectedstyle(mycontainersstyle);              msgstring =  msg.gettext().trim();              float count = msgstring.length();              count = (count/strlen);              int pheight = (int)(30*math.ceil(count));              mycontainer.setpreferredh(pheight);              int pwidth = (int)((3/4)*display.getinstance().getdisplaywidth());              mycontainer.setpreferredw(pwidth);              string substr;              int index = -1;              (int j = 0; j < emotions.emoticonkeys.length; j++) {                  index = msgstring.indexof(emotions.emoticonkeys[j]);                  if(index>-1)                     break;              }              if(index>-1){                  string emotiid = "";                  while(index>-1){                      int currentindex = -1;                      (int j = 0; j < emotions.emoticonkeys.length; j++) {                          index = msgstring.indexof(emotions.emoticonkeys[j]);                          if(index>-1){                              if(currentindex<0){                                  currentindex = index;                              }                              if(index<=currentindex){                                  currentindex = index;                                  emotiid = emotions.emoticonkeys[j];                              }                          }                      }                      substr = msgstring.substring(0, currentindex);                      msgstring = msgstring.substring(currentindex+emotiid.length());                      label lb;                      label emoticonlabel = new label("");                      try {                          emoticonicon = image.createimage((string) util.emotions.emoticonlist.get(emotiid)).scaled(14, 14);                          emoticonlabel = new label(emoticonicon);                      } catch (ioexception ex) {                      }                      emoticonlabel.getstyle().setbgcolor(0x6d96ad);                      if(substr.length()>emotiid.length()){                          int strlength = substr.length();                          while(strlength>0){                              if(substr.length()>strlen){                                  lb=   new label(substr.substring(0,strlen));                                  substr = substr.substring(strlen);                                  strlength = substr.length();                              }else {                                  lb=   new label(substr.substring(0));                                  strlength = 0;                              }                              lb.getstyle().setbgcolor(0x6d96ad);                              lb.getstyle().setmargin(0, 0, 0, 0);                              mycontainer.addcomponent(lb);                          }                      }                      emoticonlabel.getstyle().setmargin(0, 0, 0, 0);                      mycontainer.addcomponent(emoticonlabel);                       if(msgstring.length()!= 0){                          (int j = 0; j < emotions.emoticonkeys.length; j++) {                              try{                                  index = msgstring.indexof(emotions.emoticonkeys[j]);                              }catch (exception ex){                               }                              if(index>-1){                                  break;                              }                          }                          if(index<0 && msgstring.length()>(emotiid.length()-1)){                              int strlength = msgstring.length();                              while(strlength>0){                                   if(msgstring.length()>strlen){                                      lb=   new label(msgstring.substring(0, strlen));                                      substr = msgstring.substring(strlen);                                      strlength = msgstring.length();                                  }else {                                      lb=   new label(msgstring.substring(0));                                      strlength = 0;                                  }                                  lb.getstyle().setmargin(0, 0, 0, 0);                                  lb.getstyle().setbgcolor(0x6d96ad);                                  mycontainer.addcomponent(lb);                              }                          }                      }else {                          index = -1;                      }                  }              }else {                   int strlength = msgstring.length();                  while(strlength>-1){                      label  lb;                      if(msgstring.length()>strlen){                          lb=   new label(msgstring.substring(0, strlen));                          msgstring = msgstring.substring(strlen);                          strlength = msgstring.length();                      }else {                          lb=   new label(msgstring.substring(0));                          strlength = -1;                      }                      lb.getstyle().setmargin(0, 0, 0, 0);                      lb.getstyle().setbgcolor(0x6d96ad);                      mycontainer.addcomponent(lb);                 }              }              msgpane.addcomponent(mycontainer);              msgpane.setnextfocusdown(mycontainer);              msgpane.setnextfocusup(mycontainer);          }       }      if(sendfilestatus.containskey("sendingstatus")){          container filealertcontainer = new container(new boxlayout(2));          style filealertcontainerstyle = new style();          filealertcontainerstyle.setbgcolor(0x007bc1);          filealertcontainerstyle.setfgcolor(0x007bc1);          filealertcontainer.setunselectedstyle(filealertcontainerstyle);          filealertcontainer.setselectedstyle(filealertcontainerstyle);          filealertcontainer.getstyle().setborder(border.createroundborder(12, 5, 0x007bc1));          filealertcontainer.getstyle().setpadding(1, 1, 1, 1);          filealertcontainer.getstyle().setmargin(5,5, 5, 40);          mylabel filesendalert = new mylabel(mymidlet.setsrfilename+" has been sent");          filesendalert.getstyle().setbgcolor(0x007bc1);          filesendalert.getstyle().setmargin(0, 0, 0, 0);          filealertcontainer.addcomponent(filesendalert);          msgpane.addcomponent(filealertcontainer);          sendfilestatus.remove("sendingstatus");          conservationform.repaint();       }else if(sendfilestatus.containskey("receivingstatus")){          container filealertcontainer = new container(new boxlayout(2));          style filealertcontainerstyle = new style();          filealertcontainerstyle.setbgcolor(0x007bc1);          filealertcontainerstyle.setfgcolor(0x007bc1);          filealertcontainer.setunselectedstyle(filealertcontainerstyle);          filealertcontainer.setselectedstyle(filealertcontainerstyle);          filealertcontainer.getstyle().setborder(border.createroundborder(12, 5, 0x007bc1));          filealertcontainer.getstyle().setpadding(1, 1, 1, 1);          filealertcontainer.getstyle().setmargin(5,5, 40, 5);          mylabel filesendalert = new mylabel(mymidlet.setsrfilename+" has received");         filesendalert.getstyle().setbgcolor(0x007bc1);         filesendalert.getstyle().setmargin(0, 0, 0, 0);         filealertcontainer.addcomponent(filesendalert);         msgpane.addcomponent(filealertcontainer);         sendfilestatus.remove("receivingstatus");         conservationform.repaint();     }      style emticonsusstyle = new style();      emticonsusstyle.setborder(null);      emticonsusstyle.setborder(null);      emticonsusstyle.setbgtransparency(0);      style emtbtnustyle = new style();      emtbtnustyle.setborder(null);      emtbtnustyle.setborder(null);      emtbtnustyle.setbgtransparency(0);      emtbtnustyle.setmargin(2, 2, 75, 0);      emoticonbtn.setunselectedstyle(emtbtnustyle);      style attchmentbtnustyle = new style();      attchmentbtnustyle.setborder(null);      attchmentbtnustyle.setborder(null);      attchmentbtnustyle.setbgtransparency(0);      attchmentbtnustyle.setmargin(2, 2, 5, 0);      attachmentbtn.setunselectedstyle(attchmentbtnustyle);      style emticonssstyle = new style();      emticonssstyle.setborder(border.createroundborder(5, 12, 0xffffff));      emticonssstyle.setbgtransparency(100);      style emtbtnsstyle = new style();      emtbtnsstyle.setborder(border.createroundborder(5, 12, 0xffffff));      emtbtnsstyle.setbgtransparency(100);      emtbtnsstyle.setmargin(2, 2, 75, 0);      emoticonbtn.setselectedstyle(emtbtnsstyle);      style attachmentsstyle = new style();      attachmentsstyle.setborder(border.createroundborder(5, 12, 0xffffff));      attachmentsstyle.setbgtransparency(100);      attachmentsstyle.setmargin(2, 2, 5, 0);      attachmentbtn.setselectedstyle(attachmentsstyle);     tf = new textfield("", 40);      tf.settext(msgtext);      string[] defaultinputmodeorder = {"abc", "abc", "abc", "123"};      tf.setinputmodeorder(defaultinputmodeorder);      tf.setinputmode(defaultinputmodeorder[0]);      tf.setreplacemenu(false);      tf.setpreferredw(220);      tf.setpreferredh(25);      style inputustyle = new style();      inputustyle.setbgcolor(0xffffff);      inputustyle.setfgcolor(0x181818);      inputustyle.setbgtransparency(100);      inputustyle.setborder(border.createroundborder(12, 5, 0xffffff));      tf.setunselectedstyle(inputustyle);      style inputsstyle = new style();      inputsstyle.setbgcolor(0xffffff);      inputsstyle.setfgcolor(0x181818);      inputsstyle.setborder(border.createroundborder(12, 5, 0x4775d1));      tf.setselectedstyle(inputsstyle);     inputpane.addcomponent(tf);      inputpane.addcomponent(emoticonbtn);      inputpane.addcomponent(attachmentbtn);      button file = new button(icon);      file.addactionlistener(new actionlistener() {          public void actionperformed(actionevent ae) {              showfiles();          }      });       for(m = 0; m<emotions.emoticonkeys.length; m++){          try{              emoticonicon = image.createimage((string) util.emotions.emoticonlist.get(emotions.emoticonkeys[m]));              button emtoticons  = new button(emoticonicon);              emtoticons.setunselectedstyle(emticonsusstyle);              emtoticons.setselectedstyle(emticonssstyle);              emtoticons.setselectcommandtext(emotions.emoticonkeys[m]);              emoticonpanel.addcomponent(emtoticons);              emtoticons.addactionlistener(new actionlistener(){                  public void actionperformed(actionevent evt){                      button bt=(button)evt.getsource();                      conservationform.removecomponent(msgpane);                      tf.settext(tf.gettext()+bt.getselectcommandtext());                       conservationform.removecomponent(emoticonpanel);                      conservationform.addcomponent(borderlayout.center, msgpane);                      ishide = false;                      conservationform.repaint();                  }              });          }catch (exception ex){          }      }      emoticonbtn.addactionlistener(new actionlistener(){          public void actionperformed(actionevent evt){              if(!ishide){                  conservationform.removecomponent(msgpane);                  conservationform.addcomponent(borderlayout.center, emoticonpanel);                  conservationform.repaint();                  ishide = true;               }else {                  conservationform.removecomponent(emoticonpanel);                  conservationform.addcomponent(borderlayout.center, msgpane);                  conservationform.repaint();                  ishide = false;              }              conservationform.repaint();          }      });      if (cananswer) {`enter code here`          infopool.put("text2send", tf);          if(ishide){              conservationform.removecomponent(emoticonpanel);              ishide = false;          }          msgpane.setscrollable(true);          msgpane.setnextfocusup(mycontainer);          msgpane.setnextfocusdown(mycontainer);           tf.setnextfocusup(mycontainer);          tf.setnextfocusdown(emoticonbtn);          emoticonbtn.setnextfocusleft(tf);          emoticonbtn.setnextfocusright(attachmentbtn);          emoticonbtn.setnextfocusup(tf);          conservationform.addfocuslistener(new focuslistener() {              public void focusgained(component cmpnt) {              }              public void focuslost(component cmpnt) {              }          });          attachmentbtn.setnextfocusleft(emoticonbtn);          attachmentbtn.setnextfocusright(tf);          attachmentbtn.setnextfocusup(tf);          conservationform.addcomponent(borderlayout.center, msgpane);          conservationform.addcomponent(borderlayout.south,inputpane);      conservationform.addcommand(registercommand("send", "send", 0, 0));      if(mymsg.length()==0){          conservationform.addcommand(registercommand("back", "back",2, 2));      }else if(mymsg.length()==1){          registrationform.addcommand(registercommand("clear", "clear", 3, 3));      }      conservationform.addcommandlistener((actionlistener) this);      conservationform.show(); } 

[1]:


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -