Swinging text editor, color and highlight

I am writing an application that the user needs to write a javascript script as input, right now I have a simple JTextArea, but I would like to change it with something that will do some glare and color the code to make the script more coherent.

Do you know anything open source that does this?

thanks

+6
java text-editor swing
source share
5 answers

RSyntaxTextArea

RSyntaxTextArea is a text syntax highlighting component for Java Swing. It extends JTextComponent, so it integrates fully with the standard javax.swing.text package. It is fast and efficient and can be used in any application that needs to edit or view the source code.

RSyntaxTextArea was originally part of the text editor of an RText programmer, but is currently turning into a separate component, reusable in any Swing application.

Screenshot:

enter image description here

+10
source share

Try jEdit . This is mainly an editor written in Java, not an editor component. But perhaps you can extract the editor component from the jar file.

Just an idea.

+3
source share

The standard JEditorPane swing component will do this.

UPDATE: look at the API and tutorial

+1
source share

I think, as far as I guess, you need something other than JTextArea, so you can show different things in different colors. Well, this can be done using JTextPane or JEditorPane.

Here I provide you with a simple example of how to provide JTextPane with the specified print message and the color of this message.

You can change colors for any input text so that it can display different colors for each word.

// This is in javax.swing.JTextPane; JTextPane tPane = new JTextPane(); /* Method to put text in this textPane with colour of your choice * For this you need these classes. * import javax.swing.text.AttributeSet; * import javax.swing.text.SimpleAttributeSet; * import javax.swing.text.StyleConstants; * import javax.swing.text.StyleContext; */ protected static void appendToPane(String msg, Color c,String f) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, f); int len = tPane.getDocument().getLength(); tPane.setCaretPosition(len); tPane.setCharacterAttributes(aset, false); tPane.replaceSelection(msg); } 

So, if you call it appendToPane("HI", Color.RED, "Lucida Console") it will display the HI in red with the specified font. and if you call the word appendToPane(" THERE", Color.BLACK, "TIMES NEW ROMAN") then it will be printed in black in the same place next to Hi.

+1
source share

See what the NetBeans platform provides. I know that they release components as JAR files, but they are not available in the central Maven repo, which prevented me from using any.

0
source share

All Articles