Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Combo selection by programm and addSelectionListener
Combo selection by programm and addSelectionListener [message #457697] Sat, 02 July 2005 17:20 Go to next message
Eclipse UserFriend
Originally posted by: prokopiev.stc.donpac.ru

Hi,

I have the code:

combo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// do something
}
});
if (combo.getItemCount() > 0)
combo.select(0);

If I select any item by hand in running programm, method widgetSelected
is executed. But combo.select(0) is not call widgetSelected.

What's wrong?

--
Thanks,
Eugene Prokopiev
Re: Combo selection by programm and addSelectionListener [message #457716 is a reply to message #457697] Sun, 03 July 2005 16:24 Go to previous messageGo to next message
Boris Munivrana is currently offline Boris MunivranaFriend
Messages: 23
Registered: July 2009
Junior Member
Hi,

you should use <<if (combo.getItemCount() > 0)
combo.select(0);>> WITHIN <<public void widgetSelected(SelectionEvent e)>>
(a.k.a. WITHIN your SelectionAdapter),
otherwise it wont't work during runtime, only the one time you are
creating your enclosing class.

Regards,

Boris

Eugene Prokopiev wrote:

> Hi,

> I have the code:

> combo.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> // do something
> }
> });
> if (combo.getItemCount() > 0)
> combo.select(0);

> If I select any item by hand in running programm, method widgetSelected
> is executed. But combo.select(0) is not call widgetSelected.

> What's wrong?

> --
> Thanks,
> Eugene Prokopiev
Re: Combo selection by programm and addSelectionListener [message #457824 is a reply to message #457716] Tue, 05 July 2005 05:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: prokopiev.stc.donpac.ru

> you should use <<if (combo.getItemCount() > 0)
> combo.select(0);>> WITHIN <<public void widgetSelected(SelectionEvent
> e)>> (a.k.a. WITHIN your SelectionAdapter),
> otherwise it wont't work during runtime, only the one time you are
> creating your enclosing class.

I don't need combo.select(0) in SelectionAdapter, I need to do it in
some other places. Is there no way to select item by program and execute
widgetSelected?

Now I use:

jdbcConnections.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setupConnection(jdbcConnections.getSelectionIndex());
}
));
if (jdbcConnections.getItemCount() > 0) {
jdbcConnections.select(0);
setupConnection(0);
}

But it's ugly code.

--
Thanks,
Eugene Prokopiev
Re: Combo selection by programm and addSelectionListener [message #457843 is a reply to message #457824] Tue, 05 July 2005 19:41 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
When a selection is set by the programmer, widgetSelected() is not sent.
This is by design. You can use notifyListeners() to send the event yourself
or place the widgetSelected() code in another method and call it after the
select() and from widgetSelected().

"Eugene Prokopiev" <prokopiev@stc.donpac.ru> wrote in message
news:dad4t9$7v8$1@news.eclipse.org...
> > you should use <<if (combo.getItemCount() > 0)
> > combo.select(0);>> WITHIN <<public void widgetSelected(SelectionEvent
> > e)>> (a.k.a. WITHIN your SelectionAdapter),
> > otherwise it wont't work during runtime, only the one time you are
> > creating your enclosing class.
>
> I don't need combo.select(0) in SelectionAdapter, I need to do it in
> some other places. Is there no way to select item by program and execute
> widgetSelected?
>
> Now I use:
>
> jdbcConnections.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> setupConnection(jdbcConnections.getSelectionIndex());
> }
> ));
> if (jdbcConnections.getItemCount() > 0) {
> jdbcConnections.select(0);
> setupConnection(0);
> }
>
> But it's ugly code.
>
> --
> Thanks,
> Eugene Prokopiev
Previous Topic:Changing the background for all Widgets
Next Topic:Custom Color on ProgressBar
Goto Forum:
  


Current Time: Thu Apr 25 14:31:48 GMT 2024

Powered by FUDForum. Page generated in 0.04021 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top