Skip to main content

Auto Focus Problem

5 replies [Last post]
kinnarvasa
Offline
Joined: 2010-08-19

Hello Friends,

I am creating application for chatting, I have create similar UI as like LWUIT chat demo.
Now, I am facing issue in following point:
1) When my chat form load, it should be auto focus on last text Message of chat.
- I have add TextArea with bubble for that and when message is more then screen size then its loading but not scrolling at last message. I have try to use
mycontainer.requestFocus();
myform.revalidate();

method but I am not getting proper output.

2) I am creating similar application for Blackberry as well. In that I want to do like, when user press 'T' - it scroll to first message and when user press 'B' - it scroll to last message , when user press 'R' - it auto focus on TextField where he can reply for that chat.

Waiting for quick reply.

thanks,

Message was edited by: kinnarvasa

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mahdi_hijazi
Offline
Joined: 2010-01-15

Regarding your first question, use:
[code]Form.setFocused(Component cmp)[/code]
then
[code]Form.revalidate()[/code]

Message was edited by: mahdi_hijazi

kinnarvasa
Offline
Joined: 2010-08-19

Hi Mahdi,

Thanks for quick reply.

I try to use that, but I am still getting same issue. Here I am attaching some part of my code, if you can help me further.

private Container e;

public void init(){
chatForm = new Form();
chatForm.setLayout(new BorderLayout());
// add title container.
chatScreen = new Container(new BoxLayout(BoxLayout.Y_AXIS));
// add some commands...
chatForm.addFocusListener(this);
chatForm.registerAnimated(chatForm);
chatForm.show();
dataChanged(ADDED, 0);
}

public void dataChanged(int type, int index) {
responseReceived = true;
lastPolling = System.currentTimeMillis();
if (type == DataChangedListener.ADDED) {
chatEntries = rmsManagement.readMessageDetail(DataHolder.getSelecteedMessageIndex().getMessage_number());
int size = chatEntries.size();
for (int iter = 0; iter < size; iter++) {
addChatEntry((MessageDetail) chatEntries.elementAt(iter));
}
chatForm.setFocused(e); // after adding all element in form, the last container store in this e.
chatForm.revalidate();
}
}

private void addChatEntry(final MessageDetail entry) {
// define textArea and create bubble and set value.
e.addComponent(BorderLayout.CENTER, t); // adding textAread in container.
chatScreen.addComponent(count++, dummy);
chatScreen.replaceAndWait(dummy, e, CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300));

}

Thanks.

vprise
Offline
Joined: 2003-11-07

1. scrolling/focus works best when the form is already laid out. and visible, try invoking component.requestFocus() after the form was shown.

2. Just listen to key events and cast the keyCode to char to detect the desired character on qwerty devices

kinnarvasa
Offline
Joined: 2010-08-19

HI,

Thanks for reply.

As per your suggestion, I try that thing.

I first create form
then form.show()

then add all container in that.
maintain last container in one container e, as above in my code.

and when it comes out from the loop , I write : e.requestFocus();

But still I am facing same issue. Can you please help me little bit more for this ?

Thanks.

shankar_vn
Offline
Joined: 2009-11-03

try

[code]
layoutContainer();
getComponentForm().scrollComponentToVisible(e);
[/code]