Display AWT objects in SWT

Source: Internet
Author: User

One problem today is that jfreechart graphics should be displayed in an Eclipse plug-in, because the latter is based on java2d and the graphics should be displayed in SWT applications.ProgramThe need to use the SWT-AWT bridge to achieve, although the bridge approach will be accompanied by a decline in performance, but is always a solution.

CodeNot complex. Here is a piece:

Public   Void Createpartcontrol (composite parent) {
Parent. setlayout ( New Filllayout (SWT. Vertical ));
Composite drawarea =   New Composite (parent, SWT. Embedded );
Drawarea. setlayout ( New Filllayout ());
Frame canvasframe = Swt_awt.new_frame (drawarea );
Canvas =   New Java. AWT. Canvas () {
Public   Void Paint (Graphics g) {
Super. Paint (g );
If(Chart! = Null)
Chart. Draw (graphics2d) g, getbounds ());
}
} ;
Canvasframe. Add (canvas );
}

The key lies in the swt_awt.new_frame () method. The result is a Java. AWT. Frame object, where all the AWT content to be displayed is placed.

There seems to be very few free chart tools under BTW and SWT. You can only use jfreechart for the moment.

Update: If you want to display an AWT image with an animated effect in the swt, you 'd better put a jpanel control with a double buffer on the frame, otherwise, the image will flash significantly during motion.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.