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