It seems there is a lack of tutorials for SWT out there, at least significantly less than the amazing Swing Tutorial. Anyways . . . I was thinking of converting my partially developed app from Swing to SWT. I'm currently spending my free time testing out SWT, however a have an issue.
I currently have a class, lets say, "AppFrame"
which is something like:
public class AppFrame extends JFrame { public AppFrame(String title) { super(title);
// set-up components, etc etc }
// methods, etc etc
}
Now, this class is called from a main class, or perhaps other classes, or perhaps another project. I know you can't subclass Shell in SWT. What is the equivalent way to go about this in SWT.
I'm also on the fence about this approach versus creating an instance of JFrame/Shell and doing whatnot that way . . . but my current argument is that the Form's behaviour and set-up should be encapsulated into itself.
_______________________________________________ platform-swt-dev mailing list
1. There aren't some good tutorial, but some swt examples and snippets form the CVS in Eclipse. Just have a look.
- Swich to the CVS Perspective in Eclipse and add a new Repository Location : Host: dev.eclipse.org Repository Path: /cvsroot/eclipse user: anonymous password: in the Head you could find a lot a stuff around swt, just have a look at the projects starting with org.eclipse.swt.examples or org.eclipse.swt.snippet
2:Now, you could subclass a Shell and all class inherited from Widget in SWT but you have to override the Methode "checkSubclass" :
Just have a look at the question : Why can't I subclass SWT widgets like Button and Table?
And here is a small example:
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell;
public class JFrame extends Shell { public JFrame() { // set-up components, etc etc }
@Override protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components // super.checkSubclass(); }
public static void main(String[] args) { final Display display = new Display(); final JFrame shell = new JFrame(); final GridLayout gridLayout = new GridLayout(); shell.setLayout(gridLayout); shell.open();
shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
}
|