SWT Embedding awt/swing Control: public static void Main (string[] args) { Final Display display = new display (); Final Shell shell = new Shell (display,SWT. EMBEDDED); Frame frame = swt_awt.new_frame (shell);
Frame.setlayout (New BorderLayout ()); Frame.setbackground (Color.Blue); Frame.add (New JLabel ("I ' m Swing label."), Borderlayout.north); JButton btnclose=new JButton ("close"); Btnclose.addactionlistener (new ActionListener () { public void actionperformed (ActionEvent e) { display.syncexec(New Runnable () { public void Run () { Shell.close (); } }); } }); Frame.add (Btnclose,borderlayout.south); panel panel = new Panel (); Panel.setbackground (Color.orange); Frame.add (Panel,borderlayout.center); Shell.setsize (400, 300); Shell.open (); while (!shell.isdisposed ()) { while (!display.readanddispatch ()) { Display.sleep (); } } Display.dispose (); } Eclipse View Effects: public void Createpartcontrol (composite parent) { Composite P=new Composite (PARENT,SWT. EMBEDDED); Frame frame = Swt_awt.new_frame (p);
Frame.setlayout (New BorderLayout ()); Frame.setbackground (Color.Blue); Frame.add (New JLabel ("I ' m Swing label."), Borderlayout.north); JButton btnclose=new JButton ("close"); Frame.add (Btnclose,borderlayout.south); panel panel = new Panel (); Panel.setbackground (Color.orange); Frame.add (Panel,borderlayout.center); } Using SWT in SWING/AWT public static void Main (string[] args) { Final JFrame frame = new JFrame (); Canvas Canvas = new Canvas (); Frame.getcontentpane (). Add (Canvas,borderlayout.center); Frame.setvisible (TRUE);
Display display = new display (); Final Shell Shell =Swt_awt.new_shell (Display,canvas); Shell.setlayout (New Filllayout ()); Button button = New button (SHELL,SWT. PUSH); Button.settext ("SWT button"); Button.addselectionlistener (New Selectionlistener () { public void widgetdefaultselected (Selectionevent e) { }
public void widgetselected (Selectionevent e) { Swingutilities.invokelater(New Runnable () { public void Run () { Frame.dispose (); } }); }
}); Frame.setsize (400,300);
while (!shell.isdisposed ()) { if (!display.readanddispatch ()) { Display.sleep (); } } Display.dispose (); } SWT's transparency effect (invalid for control) public static void Main (string[] args) { Final Display display = new display (); Final Shell shell = new Shell (display,Swt.no_background); Shell.Addpaintlistener(New Paintlistener () { public void Paintcontrol (PaintEvent e) { GC GC = E.GC; ImageData imagedata = new ImageData ("qd2.jpg"); ImageData.Alpha= 90; Image image = New Image (display, imagedata); Gc.drawimage (image,0,0); } }); Shell.setsize (400,300); Shell.open (); while (!shell.isdisposed ()) { if (!display.readanddispatch ()) { Display.sleep (); } } Display.dispose (); } |