views:

630

answers:

2

I was wondering if anybody had any experience trying to run a complex SWT UI hosted inside a Swing component.

I've managed to get a very simple demo going but if anyone else has tried and failed / succeeded to do this it'd be great to learn from their experiences.

So to reiterate my application is a Swing app I wish to make use of a complex SWT UI component (drag and drop, popup windows and dialogs) - anybody managed this?

+1  A: 

I've used both Swing and SWT, although never in the same application/project before.

As long as your not trying to mix components together within the same windows I don't see any reason you can't have completely separate windows/dialogs each using a specific widget set. However, trying to mix SWT and Swing within a single window would likely never work, or at the very least cause lots of problems since both widget sets rely on completely different means of drawing/layout - Swing's components are all handled directly within Java and are completely separated from the underlying OS, while SWT explicitly relies on the underlying OS to do all (or most) of the GUI rendering. Trying to mix the two would likely cause all kinds of problems.

Of course, I'll throw out the usual "this isn't a recommended practice" response as well: Unless you have some really specific goal in mind here, mixing different widget sets in the same application is not a good idea. Swing and SWT have two completely different philosophies and underlying architectures. In fact SWT was born from the fact that IBM/OTI did not like the approach that was taken with Swing and so chose to implement their own widgets. With such contrasting approaches to GUI widgets, you're better off just choosing one and sticking with it, rather than mingling the two together.

BCunningham
+2  A: 

Mixing Swing and SWT isn't the best thing to do, but if you have no options, it's not a terribly difficult beast to slay. Just try to enforce some rules/standards throughout your code. eg. keep all dialogs in Swing (don't use a mix of both if there is no reason to), use naming conventions to differentiate between Swing and SWT components, etc.. Make sure you're well aware of the way that Swing and SWT components are handled by the OS/JVM before you start tackling any complex UI issues.

One thing to watch out for is drag and drop between Swing and SWT components. It's a bit tricky, but particularly so if you start throwing in custom data types.

The Dissonant