Hook combo box dropdown event [message #452759] |
Thu, 24 March 2005 10:32  |
Eclipse User |
|
|
|
Hello all.
I'm using a Combo widget, the contents of which depends on state in another
part of the window. The problem is that the contents are expensive to
compute,
so I'd like to only do that in a lazy fashion, just before the dropdown
list
is displayed.
Does anyone have any idea how to do this?
I've tried using a MouseListener to listen for mouseDown events, but they
are
not fired when clicking on the dropdown button.
BTW I'm on the Linux GTK platform, but of course I'm looking for a portable
solution.
Thanks.
jk
|
|
|
|
|
Re: Hook combo box dropdown event [message #452911 is a reply to message #452838] |
Mon, 28 March 2005 09:27  |
Eclipse User |
|
|
|
That's strange, the following snippet works for me with the latest swt and
gtk-2.2.4. If the following doesn't work for you and if you're using the
latest swt with gtk > 2.2.4 then please log a bug report with Platform -
SWT, thanks.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
Button button = new Button(shell, SWT.PUSH);
button.setBounds(10,10,10,10);
final Combo combo = new Combo(shell, SWT.NONE);
combo.setBounds(50,50,100,30);
combo.addListener(SWT.FocusIn, new Listener() {
public void handleEvent(Event event) {
if (combo.getItemCount() > 0) return;
for (int i = 0; i < 5; i++) {
combo.add("item " + i);
}
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
"John Krasnay" <john@krasnay.ca> wrote in message
news:63e05c129f4ca72e1e1abb52b3e82e7b$1@www.eclipse.org...
> > There isn't a way to hook a drop-down listener to a Combo. Surprisingly
I
> > couldn't find a request for this in Bugzilla, so you can log a Feature
> > Request with Platform - SWT for this if you wish.
>
> Thanks, I'll do that.
>
> > An alternative which seems almost as good (at least in your context) is
to
> > populate the list on Combo FocusIn, since this typically foreshadows the
> > list being shown. I've verified that this also works for a user that
clicks
> > directly on the Combo's drop-down button while focus is on some other
> > widget.
>
> I thought of this just after I posted. Unfortunately, it appears that if I
> update the combo while in the focus event handle, the dropdown doesn't,
er,
> drop. Might be a GTK issue.
>
> Oh well. Thanks for your help anyway.
>
> jk
>
|
|
|
Powered by
FUDForum. Page generated in 0.03952 seconds