Is there a good way to ignore the GUI so that you can use SWT or Swing?

I am writing an application with a SWT GUI at the moment, but would like end users to be able to choose between SWT and Swing. I experimented with abstracting the GUI details in front of different layers in the program, but was never satisfied with the results. Is there a consistent or good way to do this?

+7
java user-interface swing swt
source share
4 answers

Unfortunately, I do not believe that there is an API with agnostic tools or similar.

Therefore, it may be worth looking at the model-view-controller template . You need to divert so much functionality from the GUI in the controller so that the GUI components are thin and highlighted for the windowing toolkit of your choice.

This will allow you to place a Swing view instead of a GWT view (or vice versa) with minimal duplicate code.

Note also that this simplifies testing because it is as complex as possible in a controller or model.

+8
source share

If your only goal is to allow users to choose between SWT or Swing by drawing their own interface, then SWTSwing would be an option. You can program SWT and select the container for the SWT implementation at startup and adapt your class path accordingly.

SWTSwing is an implementation of the SWT API using Swing. It does the same as any embedded SWT implementation: it provides a bridge to the basic GUI API.

Why am I writing "would"? Unfortunately, the project seems dead, stuck in an incomplete implementation of SWT-3.2, although most of the work seems to be done, as you can see in the webstart demo. The sister project EoS (Eclipse on Swing) even had a prototype prototype. Therefore, I can’t recommend using it, although I like the idea.

+2
source share

Is there a consistent or good way to ignore GUI-specific code?

The answer, in short, is no.

The problem with using any particular GUI library is that each GUI comes with a set of basic design principles that affect every use of the library. Unless there are two such libraries that in each case agree with these design principles, there is no simple substitution of one GUI for another.

There are several libraries that try to impose their design on many disparate graphical interfaces under each of their designs, but these libraries require a fierce number of programs. Furthermore, an attempt to force one set of design paradigms to another is not usually successful.

Examples of such libraries are QT, wxWidgets and, of course, the AWT Java base.

In the end, you pretty much have to agree that you're going to choose a library and get stuck in it.

+1
source share

Yes, using SwingWT , a Swing implementation using SWT as a backend.

Many people prefer a higher level Swing API, but SWT uses its own widgets. This library seems to give you both.

It also allows you to run Swing applications without changes using a SWT server (since your program is already written using SWT, which will not help you, but it will be different). As described, the implementation is performed using a custom class loader that replaces Swing calls with SwingWT calls. It should be possible to let the user choose to do this.

The author does not seem to be actively developing it, but he is still considering / applying corrections received from others (most recently, in early 2012).

0
source share

All Articles