Referencing controls that are not defined in source yet

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Referencing controls that are not defined in source yet

Postby ChrisFreyer » Mon Jan 12, 2004 10:46 am

Probably a trivial answer, but... What is the right way to reference controls (in an event handler) that have not been defined yet in source? See snippet of open() method below for example of scenario:

Code: Select all
{
final Button b1 = new Button(composite, SWT.NONE);
  b1.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent e) {
      //need to access controls here
      //(such as Text field 'text1')
    }
  });
}
{
  final Text text1 = new Text(composite, SWT.BORDER);
}
ChrisFreyer
 
Posts: 3
Joined: Mon Jan 12, 2004 10:30 am

Postby lacou » Mon Jan 12, 2004 4:39 pm

Just convert your variable text1 from 'local' to 'field'. It will then become an instance variable of your class.

There is a button just for that in the property editor.
lacou
 
Posts: 15
Joined: Mon Nov 03, 2003 7:33 pm

Postby ChrisFreyer » Mon Jan 12, 2004 4:59 pm

Thanks lacou. I knew it would be something simple. In fact, I did by hand what the designer does with that button.

So many controls, so little time...
ChrisFreyer
 
Posts: 3
Joined: Mon Jan 12, 2004 10:30 am


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest