Use of the javapreview class (Preview Java code)

Source: Internet
Author: User

During IDE development, we may often need to preview the Java code (maybe a self-provided Java code template). jdt already provides such support and supports syntax highlighting, it is essentially a packaging of textviewer. It may be as follows:

Javapreview is an abstract class. We can use its subclass org. Eclipse. jdt. Internal. UI. preferences. formatter. compilationunitpreview. directly go to the Code:
/*** Create contents of the dialog. ** @ Param parent */@ overrideprotected control createdialogarea (composite parent) {composite container = (composite) super. createdialogarea (parent); getshell (). settext ("preview Java code"); // create a javapreview instance compilationunitpreview Preview = new compilationunitpreview (javacore. getdefaultoptions (), container); preview. getcontrol (). setlayoutdata (New griddata (griddata. fill_both); string filepath = "src/NET/chenxs/jnibindingstestapp. java "; ifile file = resourcesplugin. getworkspace (). getroot (). getproject ("test "). getFile (filepath); string content = ""; try {content = readstring (file, resourcesplugin. getencoding ();} catch (coreexception e) {e. printstacktrace ();} preview. setpreviewtext (content); // sets the Java code Content preview. update (); // display the formatted content return container ;}

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.