How to apply Syntax Highlighting in JTextArea

Hi folks.
At the moment my program does this:
The user can drag and drop images into an environment which corresponds creates a Java file.
So there is a panel that the user can drag images from and drop them to another panel. This in turn creates a Java file which is displayed at run time in a JTextArea.
I would like to use syntax highlighting here. I have come across a couple of similar questions in this forum but so far haven't found a great example.
Can anyone please point me to a good tutorial/example?
Many thanks.

lobrien9 wrote:
I am already using NewtBeans. I had a look at that link but I can't seem to find any information regarding using the NetBeans editor in my own application.You're probably using the NetBeans IDE as your development environment. But this IDE has been developed in a modular way, so you can reuse parts of it to build your own application. Such a framework is call a RPC (rich client platform). The NetBeans IDE itself is build on this NetBeans Platform. I just started to read about it myself, but I think it's worth a try. Of course it's not a simple task to get to know this framework, but if your building Swing GUIs frequently it might be worth the effort. There are some books around about this topic. Search the NetBeans homepage for book references.
-Puce

Similar Messages

  • How to enable syntax highlighting for jspf files on Dreamweaver CS5.5 on Mac

    I ran into an issue where I couldn't get the color coding (color coding style) for java server pages fragments (.jspf) files to show syntax highliting.
    I followed the adobe instructions on Changing and adding file extensions recognized by Dreamweaver without any luck.
    Here is the solution that worked for me:
    On a Mac:
    1. Edit the /Users/YOUR USER/Library/Application Support/Adobe/Dreamweaver CS5.5/en_US/Configuration/DocumentTypes/MMDocumetTypes.xml
    Note: the Adobe instructions tell you to edit /Applications/Adobe Dreamweaver CS5.5/Configuration/DocumentTypes/MMDocumetTypes.xml (Editing this file didn't do anything for me, so you need to change the file above instead)
    Find,
    <documenttype id="JSP" servermodel="JSP" internaltype="Dynamic" winfileextension="jsp,jst" macfileextension="jsp,jst" file="Default.jsp" writebyteordermark="false" mimetype="text/html">
    Replace with,
    <documenttype id="JSP" servermodel="JSP" internaltype="Dynamic" winfileextension="jsp,jst,jspf" macfileextension="jsp,jst,jspf" file="Default.jsp" writebyteordermark="false" mimetype="text/html">
    2. Edit the /Users/YOUR USER/Library/Application Support/Adobe/Dreamweaver CS5.5/en_US/Configuration/Extensions.txt
    In the All: section on top add the jspf extention right after jsp in my example it looked like this
    HTM,HTML,SHTM,SHTML,HTA,HTC,XHTML,STM,SSI,JS,JSON,AS,ASC,ASR,XML,XSL,XSD,DTD,XSLT,RSS,RDF, LBI,DWT,ASP,ASA,ASPX,ASCX,ASMX,CONFIG,CS,CSS,CFM,CFML,CFC,TLD,TXT,PHP,PHP3,PHP4,PHP5,PHP-D IST,PHTML,JSP,WML,TPL,LASSO,JSF,VB,VBS,VTM,VTML,INC,SQL,JAVA,EDML,MASTER,INFO,INSTALL,THEME,CONFIG,MODU LE,PROFILE,ENGINE,SVG:All
    and I added the jspf and it looks like this now,
    HTM,HTML,SHTM,SHTML,HTA,HTC,XHTML,STM,SSI,JS,JSON,AS,ASC,ASR,XML,XSL,XSD,DTD,XSLT,RSS,RDF, LBI,DWT,ASP,ASA,ASPX,ASCX,ASMX,CONFIG,CS,CSS,CFM,CFML,CFC,TLD,TXT,PHP,PHP3,PHP4,PHP5,PHP-D IST,PHTML,JSP,JSPF,WML,TPL,LASSO,JSF,VB,VBS,VTM,VTML,INC,SQL,JAVA,EDML,MASTER,INFO,INSTALL,THEME,CONFIG,MODU LE,PROFILE,ENGINE,SVG:All
    That's it, Quit Dreamweaver and open it up again. Open the .jspf file and see the color coding (syntax highlighting)
    Hope this helps you and seves you time figuring it out. If this helped, do a good thing, next time you figure something out, tell others about it to save their time too, like I did. Enjoy.

    TheGrandNabib wrote:
    I don't seem to have a user Library folder, my only Library folder is on the same level as my Users folder.
    From Locating your personal configuration folder in the Dreamweaver FAQ:
    In Mac OS X (Lion and Mountain Lion), open Finder and press Shift-Cmd-Go. Type ~/Library/Application Support in the dialog box, and click Go. You should then be able to find the configuration folder.

  • How to install Syntax highlighting

    Okay, so I'm trying to get syntax highlighting for my jscrollpane, which I have been lead to use: http://ostermiller.org/syntax/
    I downloaded the jar file, but I was wondering what do I have to do to start using the classes, I'm completely losses, I don't even know where to put it.

    Well I don't know if this is the right way, but it seems to be at least going somewhere. I extracted the files of the jar file and put the all the extracted folder into the class folder of my current program. Then I tried to import the package with
    import com.Ostermiller.Syntax.*;and when I complied it, it works so far.
    but when I try to create an object it can not access it:
    ToHTML toHTML = new ToHTML(); gets this error message,
    --------------------Configuration: TEV3 - j2sdh1.4.2_13 <Default> - <Default>--------------------
    C:\Program Files\Xinox Software\JCreatorV4LE\MyProjects\TEV3\src\TEV3.java:22: cannot access com.Ostermiller.Syntax.ToHTML
    bad class file: C:\Program Files\Xinox Software\JCreatorV4LE\MyProjects\TEV3\classes\com\Ostermiller\Syntax\ToHTML.class
    class file has wrong version 49.0, should be 48.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    ToHTML toHTML = new ToHTML();

  • Syntax highlight in JTextArea

    Hellu everyone
    I have a JTextArea in my simple editor. I want a simple highlighting in this editor, and I still want to use my JTextArea, and not any Textpanes or so.
    The highlighting is very simple....there are 2 words that should be bold, and comments (starts with --, and continues the rest of the line) should be in a green color.
    If possible, I also want a function to view linenumbers at the left side of the JTextArea.
    Anyone who come up with a good solution, will be awarded with 10 duke dollars!
    best regards
    Emil Erlandsson

    You actually can set highlight if you know the word's position. Our application does highlight a specific line by using setSelectionStart and setSelectionEnd.
    However, I don't know whether you can set selection on two places (never try that). You could try it and let me know :)
    Good luck.

  • JSP Syntax Highlighting

    Does anyone know how to configure Syntax highlighting for JSP's in JDeveloper v3.2?
    Thanks
    Mark

    You need a plugin which supports JSP.
    MyEclipse does (along with a lot of other stuff)
    Lomboz also provides a jsp editor
    You can find a whole lot of eclipse plugins at
    http://www.eclipseplugincentral.com/
    http://eclipse-plugins.2y.net/eclipse/index.jsp
    Cheers,
    evnafets

  • How do I enable syntax highlighting for jspf files on Dreamweaver CS6 on Windows?

    I followed the instructions (which I modified for CS6) in this posting: http://blog.metameister.com/blog/2011/04/08/open-new-file-types-and-add-syntax-highlightin g-in-dreamweaver-cs5-on-window…
    but it did not work for CS6.
    How do I enable syntax highlighting for jspf files on Dreamweaver CS6 on Windows 7?
    cheers
    Marvin in Edmonton

    Ok, I figured it out after hunting for a few hours.
    Step 1. Add the File Type
    In Dreamweaver’s toolbar:
    Select Edit > Preferences; 
    under File Types / Editors, add .jspf to the line “Open in Code View:”.
    Step 2. Extensions.txt
    Add file type .jspf to the Extensions.txt files. There are two of these files:
    C:\Users\[username]\AppData\Roaming\Adobe\Dreamweaver CS6\en_US\Configuration
    C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS6\configuration
    Step 3. MMDocumentTypes.xml
    Add jspf to the MMDocumentTypes.xml files. Open this file in Notepad or Text Editor. Do not modify the Dreamweaver configuration files within Dreamweaver.
    There are three MMDocumentTypes.xml files to be modified: 
    C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS6\configuration\DocumentTypes
    C:\Users\mhaagsma\AppData\Roaming\Adobe\Dreamweaver CS6\en_US\Configuration
    C:\Users\mhaagsma\AppData\Roaming\Adobe\Dreamweaver CS6\en_US\Configuration\DocumentTypes\
    Step 4. Restart Dreamweaver
    Hopefully the file type will now be recognized and appear with syntax highlighting.

  • Syntax highlighting in JSPs: How do they do that?

    In this forum, for example, if write code tags you write Java code that is automatically highlighted:// a comment
    public static void Main( String args[] )
       /* blah blah blah*/
    }which is great!
    I'd like to know how it's done, esp if there's a generic prcedure to it as I'm developing a site that will require syntax highlighting for several languages.
    Thanks JSP gurus!

    You can do this yourself. Create a table of key
    words. You can scan
    through the text to get the individual words. If they
    are in your
    table then add the bold tags. The trickiest part
    would be finding
    the end of comments, but this is not too difficult
    either.Yeah, this really isn't too difficult, having finished something myself. With comments, if you open with a //, you can simply consider everything between that and a newline as a comment, and with the /* comment, everything between it and a */ is also a comment.
    If all goes well, and you plan everything out, you should be able to place all necessary code formatting tags into the code with one iteration.

  • Nano syntax highlighting: catch-all syntax for configuration files

    After years of using nano, I only recently learned that it supports syntax coloring... (Why would they turn that off by default? ) Well, I thought I'll make up for it by making extra good use of it from now on...
    Unfortunately it didn't ship a highlighting syntax for the the kind of files that I use nano the most for: system configuration files.
    So I wrote my own, and after tweaking a bit here and there whenever I encountered a config file for which the highlighting wasn't satisfactory at first, I think the result is now good enough (screenshots below) that it's worth sharing with my fellow Arch users:
    Code & Instructions:
    Here is the syntax definition:
    # config file highlighting
    syntax "conf" "(\.(conf|config|cfg|cnf|rc|lst|list|defs|ini|desktop|mime|types|preset|cache|seat|service|htaccess)$|(^|/)(\w*crontab|mirrorlist|group|hosts|passwd|rpc|netconfig|shadow|fstab|inittab|inputrc|protocols|sudoers)$|conf.d/|.config/)"
    # default text
    color magenta "^.*$"
    # special values
    icolor brightblue "(^|\s|=)(default|true|false|on|off|yes|no)(\s|$)"
    # keys
    icolor cyan "^\s*(set\s+)?[A-Z0-9_\/\.\%\@+-]+\s*([:]|\>)"
    # commands
    color blue "^\s*set\s+\<"
    # punctuation
    color blue "[.]"
    # numbers
    color red "(^|\s|[[/:|<>(){}=,]|\])[-+]?[0-9](\.?[0-9])*%?($|\>)"
    # keys
    icolor cyan "^\s*(\$if )?([A-Z0-9_\/\.\%\@+-]|\s)+="
    # punctuation
    color blue "/"
    color brightwhite "(\]|[()<>[{},;:=])"
    color brightwhite "(^|\[|\{|\:)\s*-(\s|$)"
    # section headings
    icolor brightyellow "^\s*(\[([A-Z0-9_\.-]|\s)+\])+\s*$"
    color brightcyan "^\s*((Sub)?Section\s*(=|\>)|End(Sub)?Section\s*$)"
    color brightcyan "^\s*\$(end)?if(\s|$)"
    # URLs
    icolor green "\b(([A-Z]+://|www[.])[A-Z0-9/:#?&$=_\.\-]+)(\b|$| )"
    # XML-like tags
    icolor brightcyan "</?\w+((\s*\w+\s*=)?\s*("[^"]*"|'[^']*'|!?[A-Z0-9_:/]))*(\s*/)?>"
    # strings
    color yellow "\"(\\.|[^"])*\"" "'(\\.|[^'])*'"
    # comments
    color white "#.*$"
    color blue "^\s*##.*$"
    color white "^;.*$"
    color white start="<!--" end="-->"
    To install, save the above above code snippet as a file called conf.nanorc in the folder /usr/share/nano/ (or /usr/local/share/nano/ or similar if you feel strongly about the /usr <--> /usr/local separation), and then add the following to the end of the file /etc/nanorc:
    ## Configuration files (catch-all syntax)
    include "/usr/share/nano/conf.nanorc"
    Hints:
    The colors I chose look good (imo) with the terminal background and color settings that I use, but might not look good, or even readable, with yours, so simply change the color names in the code snippet to whatever you prefer - valid color names are:
    If you use a console with white background, you'll have to change at least the white color I chose for comments and punctuation.
    The first code line in the snippet includes a regular expression that defines for which file names this syntax highlighting should be used. Whenever you encounter a config file that is not matched by this, but you would still like to open it with syntax highlighting, you can manually select this syntax with nano's -Y switch, like so:
    nano -Y conf myConfigFile
    Technical Note:
    It's implemented as a single catch-all syntax, since nano chooses which syntax to apply based on the filename, and in the case of config files usually not much can be learned about the content format from the file name extension (.conf can by anything from flat key/value tuples to XML, .ini can be the official INI format or something else, etc...).
    This means that some compromises have been made, so with this highlighting syntax probably no config file looks 100% as good as a highlighting syntax that would be specifically optimized for one kind of config format, but all in all the vast majority of config files should look pretty good.
    Screenshots:
    /etc/rc.conf,  /etc/hosts:
    /etc/pacman.conf,  /etc/group:
    xorg.conf,  some .desktop file:
    httpd.conf (Apache config),  php.ini:
    More screenshots:
    /etc/fonts/fonts.conf (uses XML)
    /etc/inittab
    /etc/fstab
    /etc/inputrc
    /etc/mime.types
    /etc/protocols
    /etc/xinetd.conf
    See Also:
    nano syntax highlighting: GNU makefiles
    Update [2012-01-28]: Made some more improvements to the syntax definition (see post)
    Last edited by sas (2012-02-01 15:26:43)

    doug piston wrote:I deal with alot of .mk files and would love to see it there.
    You mean GNU makefiles?
    I'm afraid they might be out of scope for this generic config-file syntax.
    Logically they're not system config files, and technically they're a pretty specialized and complex format (different "types" of rules, rules spanning multiple lines, rules containing arbitrary Bash code, etc.).
    This is how an .mk file currently looks with this highlighting syntax:
    $ nano -Y conf /usr/lib/httpd/build/rules.mk
    And apart from highlighting variables of the form $$abc or $(abc), I'm not sure how much can be improved here without breaking the highlighting for more conventional config files.
    It would probably be better to create a specialized highlighting syntax just for .mk files.
    EDIT: I sat down and did just that, here's the result: nano syntax highlighting: GNU makefiles, and here is how the above makefile snipped looks with it:
    Last edited by sas (2012-02-01 15:18:52)

  • Repainting question for my syntax highlighter

    Hello there,
    I have a syntax highlighter which reuses much of the very useful code developed by Claude Dugauy, which can be found at http://www.fawcette.com/javapro/2003_07/magazine/columns/visualcomponents/default_pf.aspx
    . The syntax highlighting uses regular expressions, so its easily extendable to meet your needs.
    However, there is one problem: whenever the user presses a key, the whole of the TextPane containing the highlighted text, is repainted in its entirety. This is fine for small amounts of text to be highlighted, but is very slow when it comes to 1000+ lines.
    Please could someone be so excellent as to tell me how to go about addressing this problem, so that only a small amount of text is repainted whenever the user types something into the TextPane e.g. that inside the current viewport, or just the last typed word - thus removing this problem of inefficiency.
    Thanks in advance,
    Edd.

    I don't think it's going to be that easy. Every time a change is made, the default style is applied to the whole document, then the whole document is copied into a String so it can be reparsed and have the syntax styles applied again. Even if you could limit what actually gets painted, you'd still have all that unnecessary work going on.
    You could try forcing the highlighter to only reparse a portion of the document--like,say, a hundred lines before and after the point where the edit occurred--but deciding exactly where to start and stop can be pretty tricky.

  • Syntax Highlighting for custom file extensions

    Hi everyone.
    I am currently working on a PHP project, and we are using
    *.thtml files for templates. The file isn't supported by
    Dreamweaver, as it's a fictional file extension. First I couldn't
    even open it with Dreamweaver, but after I added it in
    settings/file types, it worked.
    Now my question - how can I activate syntax highlighting for
    this filetype? It contains HTML and PHP, so it should work with the
    same highlighter as all the other file types do..
    Can someone help me out?
    Thanks.
    - Chris

    Got it
    http://alexle.net/archives/119

  • Syntax highlighting not working on PL/SQL developer tool

    Hello,
    Syntax highlighting is not working on PL/SQL developer tool using the beautifier. When I go set Syntax highlighting parameters (from  EDIT>PL/SQL Developer Beautifier Options > User Interface> Editor> Syntax Highlighting ) and click apply, the changes are not reflected in SQL code in the SQL window. Other feautures in the beautifier such as Fonts, Window types are working fine.
    Please help me with this issue.
    Thanks!!
    Shreejit

    As this is not an Oracle related question (let alone Oracle SQL or PL/SQL), and as you've been given a link to the relevant website... I'll now lock this thread.

  • [SOLVED] VIM: different syntax highlighting for new vs existing file

    I've had this minor nagging issue for a while that I've been trying to figure out, but I just don't know where to look.
    It is most obvious with LaTeX files (*.tex).  When I create a new file with "vim file.tex" it is recognized as a latex file and I get syntax highlighting, but it seems odd, or off.  When I close then reopen the same file, it gets "propper" syntax highlighting.
    I gather that this must be because of the two different mechanisms for matching the syntax type: filename versus content.  When the file is new, vim only uses the extension.  Once there is a latex comand (e.g., "\documentclass{article}") it recognizes it as something else and the highlighting style is different.
    It turns out just by actually elaborating exactly what the problem was, I was able to find the solution.  I looked for how vim recognizes the files, and found two relevant lines in /usr/share/vim/vim73/filetype.vim on lines 2093 and 2094.  Apparently the .tex filetype is not the same as .latex and others.  I changed it so it was, and I got the desired behavior.
    I thought about just not posting this - but it may be useful for others.

    You're right about it being overridden.  This change should be able to be placed in ~/.vimrc though.
    Well  that was foolish - I should have read the comments right below in that file.  It says exactly how to set it in vimrc.  I've now added the following to my ~/.vimrc and this is completely solved without modifying the /usr/... file.
    let g:tex_flavor = "tex"
    Last edited by Trilby (2013-03-29 16:11:26)

  • Unable to apply syntax for upper case in pdf form

    Hi All,
    I am unable to apply syntax in adobe livecycle design to conver the case automatic in upper case.
    Please help me how to do this as I am selecting form calc , clien and pasting the script but it does not work.
    or please share me your email id so that I can share my pdf form.
    Regards,
    Md Afsar

    The upper method needs a parameter.
    Use this script.
    $ = Upper($)

  • Syntax highlighting using JTextPane

    Hello,
    Does somebody know how to achieve quick, efficient syntax highlighting using JTextPane. I have tried it out by actually removing and reinserting the colored text, but it is way too slow. It is worse if I do it in a thread. It will be a great help if somebody bails me out of this problem.
    S. Senthil kumar

    Let me see if I understand your problem...you are attempting to open a fairly large file and then highlight certain portions of the text. You're asking for help on how to efficiently do this and several people gave you links on how to highlight text which leads to your last question about the files taking too long to load. How big are these files you're talking about and how long does it take for them to load? What time is acceptable? Remember, all commercially available document display programs have a certain load time which grows larger as the document it is attempting to display grows in size.
    -Kevin

  • How to apply an adjustment, make edits, then delete the adjustment (but keep the edits)?

    I've got a photo that was shot at a crooked angle which I tried correcting using the Straighten tool in CS5 Extended but the straightened version crops out far too much of the image for my liking.  So I manually rotated and cropped the photo so that it's straight and still includes what I want it to but of course I was left with large white spaces on all four corners of the photo.  After a lot of work I was able to fill in all the white spaces manually using the clone stamp and it looks fine the way it is now on my monitor but when the image is lightened even slightly many obvious cloning flaws begin to show and I'm afraid that people with monitors that display the image lighter will be able to see the obvious cloning work I did.
    So what I'd like to do is apply a layer or mask or filter that uses the Shadows/Highlights feature to lighten the image enough to expose everything and then use that lightened over-exposed version to make the necessary fixes with the clone stamp tool and fix all the flaws that show when the image is lighter -- then, after having fixed the cloning flaws, I'd like to get rid of the Shadows/Highlights layer/mask/filter so that the photo goes back to its original exposure, except this time with the flaws fixed.  I'm still fairly new to CS5 and I haven't found a way to do this yet.  So far every time I apply Shadows/Highlights using a layer or filter I either can't do the cloning work on the lightened image or I can but then it won't let me get rid of the Shadows/Highlights after the cloning work is done.
    Is there any way around this?
    Thanks in advance for any help!

    Try using the new Edit - Fill - Content Aware feature to fill corners exposed by the rotation.  Select first, taking a few pixels of the image as well in the selection, then try the fill.  You may need to touch things up a bit after, but I'm betting it will get you there more quickly than with manual cloning.
    I tried this but unfortunately kept getting the error: "Could not fill because there's not enough data to fill it in a Content-Aware manner."
    My solution is a custom bright color profile that I toggle with Ctrl + Y which is a shortcut for Color Proofing.
    Here's how to do it.
    Edit > Color Settings (Shift + Ctrl + K). In the Working Spaces section, using the RGB menu, scroll up and choose Custom RGB...
    For the name type myBrightRGB , change the Gamma to 0.75, and press OK
    From the same RGB menu, scroll up and choose Save RGB...  and save the profile in this location C:\Windows\System32\spool\drivers\color
    Click the Cancel button in the Color Settings
    With an image open, go to View > Proof Setup > Monitor RGB, then View > Proof Setup > Custom...  and from Device to Simulate menu choose myBrightRGB profile and press OK.
    From now on toggle the Color Proof with Ctrl + Y to edit your image in the prefered color space.
    This is also a perfect solution for checking how images will look on overbright miscalibrated displays.
    Sounds like a great solution, however after following all those steps I'm not seeing an option for "myBrightRGB" anywhere in the drop down menu next to Device to Simulate.  I tried restarting Photoshop, still not there.  I did notice that in the C:\Windows\system32\spool\drivers\color folder that "myBrightRGB.csf" was the only csf file in there -- all the rest of the files in that folder are ICC files.  Not sure if that makes a difference as far as this is concerned.  When I go to View > Proof Setup > Custom, the Customize Proof Condition window has an option to "Load..." and I tried selecting the myBrightRGB file that way but it'll only load .PSF files.  Is there something I'm missing?

Maybe you are looking for

  • Can we  update The extended VBPA database table using BAPI

    Hi,   We have a table VBPA appended with two fields start date and end date. Our scenario is to when modifying the sales order using the bapi BAPI_SALESORDER_CHANGE we need to update the two fields star_date and end_date of VBPA table for the corresp

  • BEX Analyzer in Trial Version

    Hi everybody, I installed ABAP Trial Version 7.0 on my laptop, with 3 gigs of ram under Windows XP SP2. I also use MS Office 2007. My intension for now is to use the BW functionality. The RSA1 transaction works very fine. All other related functional

  • Printing Whole page problem

    I know this is probably VERY easy once you know how but how do you use AS2 to let the user simply print the view of the whole of the page (stage) they are seeing?

  • ERP Screen Response Times

    One of our clients is accessing his ERP system through a satellite WAN. Could somebody please let me know the ideal respose time for an ERP screen accessed by a satellite at a bandwidth of 512 kbps for one user?

  • Git, Main project and library project

    I use git for version control, eclipse+flex builder for flex development. I created a library prject 'core' and a main project 'base' which uses 'core'. so my question is, how can I manage the 2 projects with Git, whena new developer check out 'base'