Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ToolItem SelectionEvent
ToolItem SelectionEvent [message #454805] Fri, 29 April 2005 13:38 Go to next message
Eclipse UserFriend
Originally posted by: mek.mekistory.de

I have a toolBar with two toolItems (1 and 2), both with radio-style and
SelectionListener(SelectionAdapter)

If I press toolItem1 the code inside the SelectionListener will be executed,
ok.

But if I press toolItem2 the code inside toolItem1s SelectionListener will
also be executed again.

I've tried to remove the SelectionListener of toolItem1 when the end of the
code is reached, but without success. Nothing changes.

Thanks For Your Help.
Re: ToolItem SelectionEvent [message #454834 is a reply to message #454805] Fri, 29 April 2005 18:40 Go to previous messageGo to next message
Emil Crumhorn is currently offline Emil CrumhornFriend
Messages: 169
Registered: July 2009
Senior Member
Radiobuttons are by default grouped. Just check to see which button has the
selection to determine what was clicked, like:

public static void main(String args []) {
Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setLayout(new FillLayout());
shell.setSize(150, 150);

// two buttons
final Button a = new Button(shell, SWT.RADIO);
a.setText("A");
a.setData("Button A");
final Button b = new Button(shell, SWT.RADIO);
b.setText("B");
b.setData("Button B");

a.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
System.err.println("I pressed " + (a.getSelection() ? "a" :
"b"));
}
});

shell.open();

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

Emil


"Marco Kohns" <mek@mekistory.de> wrote in message
news:d4tdk2$b90$1@news.eclipse.org...
>I have a toolBar with two toolItems (1 and 2), both with radio-style and
>SelectionListener(SelectionAdapter)
>
> If I press toolItem1 the code inside the SelectionListener will be
> executed, ok.
>
> But if I press toolItem2 the code inside toolItem1s SelectionListener will
> also be executed again.
>
> I've tried to remove the SelectionListener of toolItem1 when the end of
> the code is reached, but without success. Nothing changes.
>
> Thanks For Your Help.
>
Re: ToolItem SelectionEvent [message #454902 is a reply to message #454834] Mon, 02 May 2005 12:56 Go to previous message
Eclipse UserFriend
Originally posted by: mek.mekistory.de

Thanks Emil. I added an if(tool_Item.getSelection) to each toolItem Code.
Now it works. Thank You

"Emil Crumhorn" <crumhorn@speakeasy.net> schrieb im Newsbeitrag
news:d4tvb7$3r5$1@news.eclipse.org...
> Radiobuttons are by default grouped. Just check to see which button has
> the selection to determine what was clicked, like:
>
> public static void main(String args []) {
> Display display = new Display();
> Shell shell = new Shell(display, SWT.SHELL_TRIM);
> shell.setLayout(new FillLayout());
> shell.setSize(150, 150);
>
> // two buttons
> final Button a = new Button(shell, SWT.RADIO);
> a.setText("A");
> a.setData("Button A");
> final Button b = new Button(shell, SWT.RADIO);
> b.setText("B");
> b.setData("Button B");
>
> a.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event event) {
> System.err.println("I pressed " + (a.getSelection() ? "a" :
> "b"));
> }
> });
>
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
> Emil
>
>
> "Marco Kohns" <mek@mekistory.de> wrote in message
> news:d4tdk2$b90$1@news.eclipse.org...
>>I have a toolBar with two toolItems (1 and 2), both with radio-style and
>>SelectionListener(SelectionAdapter)
>>
>> If I press toolItem1 the code inside the SelectionListener will be
>> executed, ok.
>>
>> But if I press toolItem2 the code inside toolItem1s SelectionListener
>> will also be executed again.
>>
>> I've tried to remove the SelectionListener of toolItem1 when the end of
>> the code is reached, but without success. Nothing changes.
>>
>> Thanks For Your Help.
>>
>
>
Previous Topic:How to use achieve Thread.sleep behavior without freezing app?
Next Topic:swt port of JGoodies' Animation?
Goto Forum:
  


Current Time: Sat Apr 20 00:20:35 GMT 2024

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

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

Back to the top