how can i implement syntax coloring on a jtextpane

kristoffer gaming

I'm making a code editor in java, and I ran into a problem while implementing syntax coluring. I could not find anything on the Internet on how to do it. I only found a 6 year old post that did not work. Can anyone help?

Holis

first: you need to use a jEditorPane

Second: Create a highlighter like this(you can change the color of the highligthe):

DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 0, 0, 75));

Third: to highlight use this

 try {
    jEditorPane1.getHighlighter().addHighlight("here put the number of the starting character", "Here put the ending number of character",
                                highlightPainter);
 } catch (BadLocationException ex) {
 }

Example.

  JEditorPane text = new JEditorPane();
  text.setText(" Hi This is example good");
  DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 0, 0, 75));
  try {
    jEditorPane1.getHighlighter().addHighlight(3, 7, highlightPainter);
 } catch (BadLocationException ex) {
 }

It should apper this underlined: "i This ";

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how can I coloring php syntax in vscode?

From Dev

How can I add Pascal Syntax Coloring to Xcode 5?

From Dev

How does syntax coloring work

From Dev

How can I get access to the JTextPane content from a JMenuItem?

From Dev

How can I alternate coloring between table bodies? CSS

From Dev

How can I implement IServiceProvider?

From Dev

How to provide Python syntax coloring inside Webstorm?

From Dev

Eclipse and Pydev - how to edit syntax coloring choices

From Dev

How to set custom syntax coloring for PowerShell 5.0?

From Dev

How do I implement Rouge syntax highlighting in Rails?

From Dev

How can i implement a scanning bar animation?

From Dev

How can I implement this logic better

From Dev

How can I implement a RESTful Progress Indicator?

From Dev

How can I implement a '-Help' switch in PowerShell?

From Dev

Load balancing server, how can I implement it?

From Dev

How can I implement OnClickListener of an ImageView in a fragment?

From Dev

How can I implement comparable interface in go?

From Dev

How can I implement a dynamic selection?

From Dev

How can I implement asyncio websockets in a class?

From Dev

How can I implement a fixed size hashmap?

From Dev

How can I implement the observer pattern in Rust?

From Java

How can I implement PageView in SwiftUI?

From Dev

How can I implement @Singleton annotation?

From Dev

how can I implement java EOF

From Dev

How can i implement the promise pattern with ReactiveCocoa?

From Dev

How can I implement $http in Typescript?

From Dev

How can I implement grouping preference in antlr?

From Dev

how can i implement "or" in scheme in different ways

From Dev

How can I implement a Multi-DataTriggerBehavior

Related Related

HotTag

Archive