Sunday, September 2, 2012

Embed Swing and AWT in SWT

I am looking for a way to draw dynamic diagrams in SWT. I have found a very power Java library called JFreeChart. Unfortunately it support Swing better than SWT. Therefore I need a way to embed Swing into my SWT GUI.

I have discovered that SWT provides an very easy way to do so.For many SWT components, they have a attribute called SWT.EMBEDDED. By adding this attribute, the component knows that another application is plugged in.

Here is an example of this function.

Display display = new display();
Shell shell = new shell(display, SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame(shell);
frame.add(new JLabel("This is a Java Swing Label"));

1 comment:

  1. Don't spend too much time on a particilar task. If you are stuck, move on. There are still a number of tasks to do for the whole projects, such as generate report after testing, integrating with the back-end for a formal TPC-C test.....