Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to define actions for dynamic buttons
How to define actions for dynamic buttons [message #440449] Fri, 30 July 2004 19:43 Go to next message
Yiqun Xu is currently offline Yiqun XuFriend
Messages: 12
Registered: July 2009
Junior Member
Hello all,

I have generated dynamic buttons on a shell--the number of buttons is
flexible. it is quite upset when I found it is kind of hard to define
correspondingly dynamic actions for each button--maybe it is not that
difficult but I just do not know how. The following is my code and error
messages I got:

for ( int i=0; i<subImageNum; i++){
button[i] = new Button(composite,SWT.PUSH);
...
button[i].addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {

callAnotherAction((Button)(e.item)); // Error: e.item is null

callAction(i); // Error:cannot refer to a non-final variable i
// inside an inner class defined in a different
// method

shell.close();
}
});
}

Thank you in advance!

Rich
Re: How to define actions for dynamic buttons [message #440453 is a reply to message #440449] Fri, 30 July 2004 21:14 Go to previous message
Yiqun Xu is currently offline Yiqun XuFriend
Messages: 12
Registered: July 2009
Junior Member
I got it, using a little trick:

final String s=""+i;
.....
callAction(s);


Rich wrote:

> Hello all,

> I have generated dynamic buttons on a shell--the number of buttons is
> flexible. it is quite upset when I found it is kind of hard to define
> correspondingly dynamic actions for each button--maybe it is not that
> difficult but I just do not know how. The following is my code and error
> messages I got:

> for ( int i=0; i<subImageNum; i++){
> button[i] = new Button(composite,SWT.PUSH);
> ...
> button[i].addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {

> callAnotherAction((Button)(e.item)); // Error: e.item is null

> callAction(i); // Error:cannot refer to a non-final variable i
> // inside an inner class defined in a different
> // method

> shell.close();
> }
> });
> }

> Thank you in advance!

> Rich
Previous Topic:TableTree Question
Next Topic:getting access to nsIWebBrowser
Goto Forum:
  


Current Time: Fri Apr 26 18:55:24 GMT 2024

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

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

Back to the top