Skip to main content

TextField and Autocomplete

3 replies [Last post]
nafs
Offline
Joined: 2008-06-10

Hi guys

I am implementing Autocomplete feature based on the guidelines presented in Shai's blog post ( http://lwuit.blogspot.com/2008/06/lightweight-text-input-in-lwuit.html )

In my current application, I already have my own custom List Model, so I have to implement the FilterProxyListModel above my model...

Anyway, I've got it all to work.. but there is 1 strange thing which I dont understand..
In order for my List to dynamically update while the user is inputting values in the TextField, I need to repaint() the Form. But in Shai's example there is no repaint() anywhere but the List still updates... how?

My only guess is that maybe the DefaultListModel implementation calls repaint() somehow... I dunno.

Message was edited by: nafs

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

Hi,
whenever the list model changes it must fire a change event on the
EDT. Someone was supposed to blog about it but is procrastinating ....

Anyway, you need to implement the add/remove*Listener methods so that
they keep all the listeners. Whenever a value in the list model
changes you need to fire the event by traversing the list of elements
and firing the event. I think posted such sample code in a previous
thread here.

The list adds itself as a data/selection listener and can thus decide
to paint itself on the fly.

Shai.

> Hi guys
>
> I am implementing Autocomplete feature based on the guidelines
> presented in Shain's blog post ( http://lwuit.blogspot.com/2008/06/
> lightweight-text-input-in-lwuit.html )
>
> In my current application, I already have my own custom List Model,
> so I have to implement the FilterProxyListModel above my model...
>
> Anyway, I've got it all to work.. but there is 1 strange thing
> which I dont understand..
> In order for my List to dynamically update while the user is
> inputting values in the TextField, I need to repaint() the Form.
> But in Shai's example there is no repaint() anywhere but the List
> still updates... how?
>
> My only guess is that maybe the DefaultListModel implementation
> calls repaint() somehow... I dunno.
> [Message sent by forum member 'nafs' (nafs)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284347
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

nafs
Offline
Joined: 2008-06-10

1)
"[i]whenever the list model changes it must fire a change event on the
EDT[/i]"
and
[i]"Whenever a value in the list model
changes you need to fire the event by traversing the list of elements
and firing the event."[/i]

What kind of event? Do you mean something like this:
public void addItem(Object o)
{
vector.additem(o)
[b]fireChangeForAllListeners()[/b]
}

void fireChangeForAllListeners()
{
for(int iter = 0; iter < listeners.size(); iter++)
Now what do I do here?
}

2)
The list adds itself as a data listener and can thus decide to paint itself on the fly

Ok 2 things. According to the docs, the DefaultListModel doesn't implement any Listeners..
Secondly... yes, in your example you are cleverly implementing the DataChangedListener, but where are you "deciding to paint itself on the fly"?

This forum is bugged, losing all my text and markup

Message was edited by: nafs

Shai Almog

Close, something more like this:
private void fireDataChangedEvent(final int status, final int
index){
if(!Display.getInstance().isEdt()) {
Display.getInstance().callSeriallyAndWait(new Runnable() {
public void run() {
fireDataChangedEvent(status, index);
}
});
return;
}
// we query size with every iteration and avoid an
Enumeration since a data
// changed event can remove a listener instance thus break
the enum...
for(int iter = 0 ; iter < dataListeners.size() ; iter++) {
DataChangedListener l = (DataChangedListener)
dataListeners.elementAt(iter);
l.dataChanged(status, index);
}
}

List (not list model) doesn't implement any listeners they are hidden
within though...

> 1)
> "[i]whenever the list model changes it must fire a change event on the
> EDT[/i]"
> and
> [i]"Whenever a value in the list model
> changes you need to fire the event by traversing the list of elements
> and firing the event."[/i]
>
> What kind of event? Do you mean something like this:
> public void addItem(Object o)
> {
> vector.additem(o)
> [b]fireChangeForAllListeners()[/b]
> }
>
> void fireChangeForAllListeners()
> {
> for(int iter = 0; iter < listeners.size(); iter++)
> [b]//Now what do I do here?[/b]
> }
>
> 2)
> [i][i]The list adds itself as a data/selection listener and can
> thus decide
> to paint itself on the fly[/i][/i]
> Ok 2 things. According to the docs, the DefaultListModel doesn't
> implement any Listeners..
> Secondly... yes, in your example you are cleverly implementing the
> DataChangedListener, but where are you "deciding to paint itself on
> the fly"?
> [Message sent by forum member 'nafs' (nafs)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284360
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net