4

I am working in a project in which user fills a questionnaire and the answers are then submitted to the server. For simplicity I have just kept two questions per screen and after clicking on the next command the user gets next two questions. I have used lwuit framework in this project.

To reduce the memory requirements I create form, questLabel1, ansCombo1,questLabel2 and ansCombo2 only once. and their properties are set as per the current frame (screen). The problem is if you are in form 2 and you scroll down to the last option and then you click the next button, since you scrolled down the form doesn't displays the upper components even on the next form tried so many thing. creating a new instance of the form may work but I don't want to use that, for obvious memory reasons,

Any other solution?

thanks in advance,

bharath
  • 14,283
  • 16
  • 57
  • 95
Amit
  • 13,134
  • 17
  • 77
  • 148
  • 1
    _the form doesn't displays the upper components even on the next form_ could you please explain the problem in more details? Are you by chance looking for functionality like one provided by [Display.setCurrentItem](http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Display.html#setCurrentItem\(javax.microedition.lcdui.Item\))? "Requests that the Displayable that contains this Item be made current, scrolls the Displayable so that this Item is visible, and possibly assigns the focus to this Item...." – gnat Jul 28 '11 at 12:34
  • 1
    @gnat: he need to do with LWUIT, not in Java ME. – bharath Jul 28 '11 at 12:46
  • thanks @gnat... but the solution u suggested is of lcdui framework, I am using lwuit and only allowed to use lwuit features.... I read the documentation of Display class of lcdui and I just need a similar method for my task... – Amit Jul 28 '11 at 12:57
  • 2
    understood. Did you check `Component`/`Container` API? javadocs I've seen at lwuit page suggest some methods with similar semantics `scrollComponentToVisible`, `scrollRectToVisible`. _"Makes sure the component is visible in the scroll if this container is scrollable..."_ stuff like that – gnat Jul 28 '11 at 13:15
  • @Bharath I suggested _like in setCurrentItem_ expecting that LWUIT provides functional mapping to most if not all features available in MIDP lcdui. IIRC in earlier versions such a mapping was even explicit with declarations (I don't recall exact details sorry) looking like `Component extends Item`. To avoid confusion note I don't complain against current lwuit design, vice versa I believe it's better without inheritance – gnat Jul 28 '11 at 15:33

3 Answers3

3

To make it scroll so that component is visible, check Component/Container API javadocs. I've seen at lwuit page these suggest some methods with semantics that fits - scrollComponentToVisible, scrollRectToVisible. "Makes sure the component is visible in the scroll if this container is scrollable..." stuff like that

  // above extracted from comment to an answer to make it more visible
  // for the case if some reader has similar problem
gnat
  • 6,213
  • 108
  • 53
  • 73
1

You can use form.refreshTheme() or form.revalidate() for refreshing your form. If you have made updates on any particular container then do the same for container as well.

Rahul
  • 172
  • 1
  • 4
1

Have you tried form.revalidate()?. Because this is useful when you modify the container hierarchy and need to redo the layout.

Update: Use requestFocus(); on first component of next form. Its automatically focused on first (Upper) component.

bharath
  • 14,283
  • 16
  • 57
  • 95
  • 1
    ya I have tried that.... the call hierarchy is 1. form.addComponent() multipe times 2. form.revalidate() 3. firstComponent.requestFocus() 4. form.show()..... is everything ok ? or I am using it wrongly ? – Amit Jul 28 '11 at 13:08
  • 1
    plz see the call sequence in my previous comment... I call requestFocus() in step 3. – Amit Jul 28 '11 at 13:30
  • @Amit: Your hierarchy is correct. Did you show the `from` again inside of `next` command action event? – bharath Jul 28 '11 at 13:38
  • NO i dont.. by the way problem is solved by the method suggested by @gnat.... and thanks for ur help too... I really appreciate... – Amit Jul 28 '11 at 13:59