Syntax colouring using Swing

Is it possible to have something like a JTextArea which will color some keywords based on some mappings I have ?


Asked by: Adelaide737 | Posted: 23-01-2022






Answer 1

Here are a few other choices that you could try

  1. http://ostermiller.org/syntax/editor.html
  2. http://java.sun.com/products/jfc/tsc/articles/text/editor_kit/index.html
  3. http://fifesoft.com/rsyntaxtextarea/
  4. http://code.google.com/p/jsyntaxpane/

Answered by: Arnold238 | Posted: 24-02-2022



Answer 2

I am not sure, because I believe JTextArea only directly supports a single font in a single color.

According to SyntaxHighlighter class article, JTextPane is the way to go.

Answered by: Sam731 | Posted: 24-02-2022



Similar questions

java - Colouring JTree's TreeNodes

I have a JTree which I give objects that implement the TreeNode interface, and a custom TreeModel to display them (not using DefaultMutableTreeNode). I would like to change the text colour of some nodes. I can't find anything in the docs, except javax.swing.tree.DefaultTreeCellRenderer.setTextNonSelectionColor(Color newColor), but it will change everything in...


swing - JAVA 6x6 grid colouring game

Hi everyone Im on to the last part now which is file reading. i have tried writing a fileReader but seem to not be changing the value of my variable rNum? any ideas on why it wont change in the following statements? thanks public void readStartFile(String fileName){ int rowNumber=-1; int colNumber = -1; int rN= 0; int cN = 0; try{ // Open the file that is the first ...


java - Colouring JComboBox

Dumb question: I am trying to colour a JComboBox - my ComboBoxRenderer getListCellRendererComponent method sometimes gets control and works fine - at other times the JComboBox is just white. This problem seems to be partly affected by whether the combobox has the focus, but my method never seems to have the boolean cellHasFocus on - even when the JComboBox as a whole seems to function as though it has focus! One id...


java - Colouring text based on color codes in a JTextPane dynamicly

I'm trying to make a textpane using a StyledDocument where when doc.insertString(doc.getLength(), text + "\n", keyWord); it replaces all instances of "§" then a number (so like "§1") with the colour and should remove the code its self after and leave the text coloured. The code is able to colour and remove but the issue is that the when I remove the text from the actual doc(the textpane) the local variable I have isn't u...


java - Colouring jtable row in netbeans

I'm new to java. What i am trying to do is to create a table that shows a list of objects. What i want is to give color for specific rows in the JTable based upon the value of the member of an object. I saw a lot of option like using "TableCellRender" and all.I have tried them too. But the problem is that am using the Netbeans IDE so that i am not creating the table by code. Can some one please help me to change row color...


java - Colouring specific letters in a String?

Closed. This question does not meet Stack Overflow guid...


java - Grid colouring game : Find the number of red and blue lines drawn

Problem Description: Walter has a grid of size N*M , initially each of the cell is white . Walter can draw a horizontal or vertical stroke which can be 1 or more cell long. Walter only draws horizontal stroke with RED colour and Vertical stroke with BLUE color Walter never draws two horizontal or two vertical stroke overlapping. If a horizontal stroke crosses vertical stroke then color of the cell is Green. Given the strin...


java - Graph Colouring program

I've been asked to create a Java program, wherein I accept a predefined number of vertices first, and then all the edges which exist in the graph as number pairs. My code is supposed to accept the edges, create the 'graph' and color all the vertices. My problem is with the coloring. The method 'setColor' is supposed to accept the degree of the graph each time it is called. The getBiggestVertex method is supposed ...


java - Colouring JavaFX Shape

I have a Scene graph which contains two buttons, one for creating rectangles and one for creating circles, there is also a slider which, when moved will change the colour of the shape objects. The shapes are also draggable. Unfortunately, the colour slider doesn't quite work the way i want it to. The idea is that once the shape is created via the button, and the shape is clicked on with the mouse, the colour of the shape w...


java - Colouring problem (with 2 colours) where each vertex has a specific area and finding min area coloured using DFS

I have a list of islands/areas, initially white. All vertices connected to each other by 1 edge must have opposite colours. (Either black or white). I wish to use the minimum amount of black to colour the islands. Each island has a different size, and index of islands start from 1. I have used DFS, and a global object to track both the white and black areas, then giving me the minimum of the two. A...






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top