4

i have questions how to make a simple text editor used for editing Java Language? Could anyone give some tips, steps, references, or something else.. I just want to make a text editor only for java language that has functions like syntax coloring, and an auto generate functions for try catch, and if else..

This is for my lesson in Java Programming..

thx for any helps.. :D

5
  • Take a look at jEdit, it's an open source text editor written in Java so you can have a look at the source and see what they do. Commented Apr 11, 2012 at 3:32
  • I already take a look at JEdit.. But perhaps its to complicated for me.. Is there any simple example? First step i just want to build syntax coloring. Commented Apr 11, 2012 at 3:42
  • Writing a syntax-aware editor involves a large amount of work. If you have to write everything from scratch it is, for one person, much more than one semester's worth of work. Especially if you are not already an expert Java developer. Is this something assigned to you or did you choose this yourself? How long do you have? Commented Apr 11, 2012 at 3:50
  • I think so, because it is quite complex for me if i make a "trully" java editor.. I choose this because i think that syntax coloring is not too complicated, so syntax coloring is my purpose in develop this program. I have maybe 3-4 months.. Commented Apr 11, 2012 at 3:56
  • I think you'd need to have a look at abstract syntax trees and parse trees and generate such a representation from the input src code using the rules defined in the java language specification. Why is this necessary? Because you cannot simply search for "int" in the src code and colour that as a primitive data type. What if the int is within a comment? Constructing these representations from scratch seems like an incredibly complex task though. Commented Apr 11, 2012 at 9:43

2 Answers 2

2

Check out JSyntaxPane.

It's an open source project which sounds like it does exactly what you're after. Looking at how someone else accomplished a task like this will probably give you lots of ideas.

Here's a screenshot of what it looks like (the panel on the right):

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

+1 Nice library. In the past, I use Netbean's editor plugin library.
@ulmangt Thx for the link.. I already take a look at the classes.. And i think that its quite complex to do.. I just want to make only syntax highlighting.. From that code, It was very professional programmer i think..
1

Check out How to Use Editor Panes and Text Panes.

Also, here are some examples - Highlighting Words in a JTextComponent and Inserting Styled Text in a JTextPane Component.

And here is one with lexer - Text Editor Tutorial

6 Comments

Thx, but i should build my own class.. I have some references like java lexer, token. I think that it will not be used when i use JEditorPanes.. is that right?
@ordinaryBoys, lexer gives you tokens. you can use token properties such as type of text and its position to apply corresponding styles in text pane.
nah, Max.. U got what i want.. I already download the syntaxdemo, and see what is inside the classes.. Uhmm, Did u already see that program? is that simple to build?
I have to learn for Lexer and Tokens.. i think that they are the keys in syntax coloring.. Is that right? Do u have links or references for lexer and tokens?
@ordinaryBoys , You may find this answer helpful.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.