Lost and Confused

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

Lost and Confused

Postby Andrew_of_New_Zealand » Tue Jul 12, 2005 2:37 am

Hello people, I'm new to Eclipse and SWT, design and software building program, God its getting me down. I'm a student in User Interface Design at Victoria Uivversity. Trying to now to learn how to build interfaces, but Eclipse and SWT all contain a lot of stuff I just can see the real use of now.

Anyway I'll ask one thing.
How do you get an on/off switch to respond to each of the 2 different states?
Andrew_of_New_Zealand
 
Posts: 8
Joined: Mon Jul 11, 2005 10:14 pm

Postby pijn_mar » Tue Jul 12, 2005 4:39 am

I think this question is better asked in the SWT beginners forum on http://www.eclipse.org.

This address might be helpfull it is just one of the many sites you can find regading swt. Google is your friend! Try SWT, snippet, tutor

http://www.cs.umanitoba.ca/~eclipse/

A good book might help too: Eg SWT and JFace (apress)

Hope this helps you get started. :-)
pijn_mar
 
Posts: 6
Joined: Thu Jun 02, 2005 10:36 pm

Postby Slot Head » Tue Jul 12, 2005 3:47 pm

As a fellow battered and bruised newbie, welcome!

I have tried getting answers in the eclipse Newcomer, SWT and JDT forums. Amazingly, I almost never get a useful answer from the eclipse experts. I think I've probably put more into that than gotten back. But still, pijn_mar is right, and I especially agree like the apres book too.

Now, if you have purchased/downloaded Instantiation's SWT-Designer, you're in luck! Not only will their best-on-the market SWT/JFace GUI designer help you get going, you'll also get far better help from their tech support staff. And if you actually find a bug, these guys are all over it and very aggressive with updates. YMMV, but this has been true for me.

Anyway, here's a crack at answering your question, assuming you are using Eclipse with SWT-Designer:

1. File, New, SWT/JFace Project
2. File, New, Other..., Designer, JFace, Application Window
3. Open that window. Notice the Source and Design tabs.
4. Click on the Design tab.
5. Visually put a Toggle Button on the screen.
6. Double click on the toggle button, and the Designer takes you into this code:
Code: Select all
   protected Control createContents(Composite parent) {
      Composite container = new Composite(parent, SWT.NONE);

      final Button button = new Button(container, SWT.TOGGLE);
      button.addSelectionListener(new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
         }
      });
      button.setText("toggle button");
      button.setBounds(110, 90, 85, 45);
      //
      return container;
   }


7. Edit the Widget selected code to look like this:
Code: Select all
         public void widgetSelected(SelectionEvent e) {
            if (button.getSelection()) {
               System.out.println("Button is down");
            }
            else {
               System.out.println("Button is up");
            }
         }


HTH
Slot Head
 
Posts: 36
Joined: Sun Jul 10, 2005 9:50 am

Postby Andrew_of_New_Zealand » Tue Jul 12, 2005 6:22 pm

Ok I guess getSelection appears to be the way out of the trap. I thought that perhaps the 'SelectionEvent e' was like an ON?OFF boolean but I guess I'll need find out what it really is,

Thanks. I'll hang around this forum for a bit
Andrew_of_New_Zealand
 
Posts: 8
Joined: Mon Jul 11, 2005 10:14 pm

Postby Eric Clayberg » Wed Jul 13, 2005 12:25 pm

Andrew_of_New_Zealand wrote:Ok I guess getSelection appears to be the way out of the trap. I thought that perhaps the 'SelectionEvent e' was like an ON?OFF boolean but I guess I'll need find out what it really is

The SelectionEvent object is basically a data object that encapsulates a variety of pieces of data about the event. It has a number of public fields that you can access. I would recommend that you look at that class itself to see what info is available.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest