Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Button loses selection event after disabled it
Button loses selection event after disabled it [message #493378] Sun, 25 October 2009 14:39 Go to next message
antonio is currently offline antonioFriend
Messages: 22
Registered: July 2009
Junior Member
Hi,

When I create a button and its relative event on click like this:

Button button = new Button(buttonBox, SWT.NONE);
button.setText("Click me");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// do something after click
}
});

works fine. Anyway, if it have been disabled somewhere in the code by:

button.setEnabled(false);

and then re-enabled with:

button.setEnabled(true);

clicking on it has no more effect. It looks like button has lost the listener.
Is it normal? Do I need to re-add selection event?

Thanks,
Julio
Re: Button loses selection event after disabled it [message #493381 is a reply to message #493378] Sun, 25 October 2009 14:44 Go to previous messageGo to next message
Remy Suen is currently offline Remy SuenFriend
Messages: 462
Registered: July 2009
Senior Member
On Sun, 25 Oct 2009 10:39:15 -0400, antonio wrote:
> Anyway, if it have been disabled somewhere in the code by:
>
> button.setEnabled(false);
>
> and then re-enabled with:
>
> button.setEnabled(true);
>
> clicking on it has no more effect. It looks like button has lost the
> listener. Is it normal? Do I need to re-add selection event?

This works fine for me on Linux/gtk+. My test code is as follows:

final Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(200, 50);
shell.setLayout(new FillLayout());

final Button b1 = new Button(shell, SWT.PUSH);
b1.setText("1");
final Button b2 = new Button(shell, SWT.PUSH);
b2.setText("2");

b1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
b2.setEnabled(!b2.getEnabled());
}
});

b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Pushed");
}
});

shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

shell.dispose();
display.dispose();

Regards,
Remy
Re: Button loses selection event after disabled it [message #493388 is a reply to message #493381] Sun, 25 October 2009 16:24 Go to previous messageGo to next message
antonio is currently offline antonioFriend
Messages: 22
Registered: July 2009
Junior Member
Hi Remy,

thanks for reply.

I tested ur code but it doesn't work for me (same problem).
When I launch it and click '2' button then "Pushed" is displayed on console. Anyway, after pressing '1' that disable '2' and finally re-enabling it after second click, '2' button doesn't work anymore, I mean everytime click it, "Pushed" is not more displayed.

I'm using SWT 3.3 on Linux/Gtk+

Upgrading SWT version is a real problem for me, cos I'm using Maven 2 and there is not a public repository hosting 3.4/3.5 version for SWT AFAIK

Julio


Thanks,
Julio
Re: Button loses selection event after disabled it [message #493390 is a reply to message #493388] Sun, 25 October 2009 16:49 Go to previous messageGo to next message
Remy Suen is currently offline Remy SuenFriend
Messages: 462
Registered: July 2009
Senior Member
On Sun, 25 Oct 2009 12:24:08 -0400, antonio wrote:
> I'm using SWT 3.3 on Linux/Gtk+

3.3 is no longer supported. You should at least download Eclipse 3.5 and
try SWT 3.5 to see if it works for you. That would at least help figure
out whether it is your system's problem or not.

Regards,
Remy
Re: Button loses selection event after disabled it [message #493406 is a reply to message #493388] Mon, 26 October 2009 01:26 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
antonio wrote:
> Hi Remy,
>
> thanks for reply.
>
> I tested ur code but it doesn't work for me (same problem).
> When I launch it and click '2' button then "Pushed" is displayed on
> console. Anyway, after pressing '1' that disable '2' and finally
> re-enabling it after second click, '2' button doesn't work anymore, I
> mean everytime click it, "Pushed" is not more displayed.
>
> I'm using SWT 3.3 on Linux/Gtk+
>
> Upgrading SWT version is a real problem for me, cos I'm using Maven 2
> and there is not a public repository hosting 3.4/3.5 version for SWT AFAIK
>
> Julio
You may be running into an incompatibility between SWT and the latest
version of Gtk.

See if the workaround in this bug fixes the problem.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=291257
Re: Button loses selection event after disabled it [message #495274 is a reply to message #493406] Wed, 04 November 2009 13:08 Go to previous messageGo to next message
antonio is currently offline antonioFriend
Messages: 22
Registered: July 2009
Junior Member
Hi,

that fix doesn't work for me. I'm using Ubuntu 9.10 Karmic.

Anyway that problem seems to be present in SWT 3.5.1 too.

any hint?

thanks,
julio


Thanks,
Julio
Re: Button loses selection event after disabled it [message #495327 is a reply to message #495274] Wed, 04 November 2009 15:20 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

Using Remy's snippet I see that this problem is fixed in the eclipse 3.6
stream but still happens in the latest 3.5.2 build. However I can make it
work in eclipse 3.5.2 by setting environment variable GDK_NATIVE_WINDOWS to
1 before running. When this variable is set GTK 2.18 reverts to some
specific pre-GTK-2.18 behaviours that SWT was dependent on. This may help
you with using eclipse 3.3 as well.

HTH,
Grant


"antonio" <antongiulio05@gmail.com> wrote in message
news:hcruc7$nol$1@build.eclipse.org...
> Hi,
>
> that fix doesn't work for me. I'm using Ubuntu 9.10 Karmic.
>
> Anyway that problem seems to be present in SWT 3.5.1 too.
>
> any hint?
>
> thanks,
> julio
Re: Button loses selection event after disabled it [message #495511 is a reply to message #495327] Thu, 05 November 2009 07:47 Go to previous message
antonio is currently offline antonioFriend
Messages: 22
Registered: July 2009
Junior Member
Hi,

I have experienced that issue with a lot of buttons in eclipse 3.4.2 and 3.5.1 with and without GDK_NATIVE_WINDOWS set. Anyway I re-updated Ubuntu 9.10 (last time was 2 weeks ago), and set it works now (same for my application using SWT 3.3).

Thanks,
Julio


Thanks,
Julio
Previous Topic:Selecting text in multiple Text widgets simultaneously with SWT.MULTI style - can I stop this?
Next Topic:Resize composites.
Goto Forum:
  


Current Time: Tue Apr 23 17:00:27 GMT 2024

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

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

Back to the top