aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextPane: Identifying Comment Lines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextPane: Identifying Comment Lines" Watch "JTextPane: Identifying Comment Lines" New topic
Author

JTextPane: Identifying Comment Lines

Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Hello All,

Please have a look the following two files.


Form.java



Keywords.java




What happens here is, when the user clicks the save button, the program will search for Java keywords and start highlighting them. As you can see, there is no way in this program to highlight comment lines! I am trying to achieve this for more than a week now.

Please help!


Are you better than me? Then please show me my mistakes..
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Any help here please? I found a way to identify "Strings" but that is also messed up when text is deleted or edited. So can't apply it to here. Please help.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
no one can compile and run the code, so what it does/doesn't do can't be seen.

why can't you search for the '//' to id the comment lines
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Michael Dunn wrote:no one can compile and run the code, so what it does/doesn't do can't be seen.



Thanks for the reply Michael. But why no one can run? I tested this code in my machine before I add it to here :confused: May be because of the packages?
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Michael Dunn wrote:why can't you search for the '//' to id the comment lines


Possible. It can be used to identify the comment entry. But the cases are:

1. When comment line is entered, I have to check for number of letters in Comment. Then only I can highlight them (Or else I can highlight the WHOLE ROW, but you know how it looks like at the end)
2. When the comment "symbol" is deleted, the WHOLE COLORED COMMENT LETTERS has to be changed to "No Colour"
3. This is only single comment. but multiple comment also there.

I used the above technique to work with Strings (identify text inside double quotations). But it also fails if the user replaced the text or deleted a PART of the text. Then what happens is, it highlights here and there, something like, first word, then the next word is left, then again the first letter of the next word, like that!!!

Please help!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> But why no one can run?

"implements KeywordConnector" I'm still on java 1.6, is this in java 7?
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Michael Dunn wrote:> But why no one can run?

"implements KeywordConnector" I'm still on java 1.6, is this in java 7?


Oh god!!! I beg your pardon!! Thanks a lot for showing that error. My goodness, I haven't uploaded it! I am in my Laptop now, will edit it when I get back to my desktop PC. Thanks again for showing that case.
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Here is the missing part

KeywordConnector.java



Sorry for the delay Michael, I had some issues with my computer. The above is the complete missing part. Please help.

can a moderator please attach this to my first post in the thread? I can't edit it, because it is not allowing me to.
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Hello all,

I really need your help here. Please help me.
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Any help here Please?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I've run the code a couple of times, typed a few words into the textpane,
and it prints out a whole bunch of stuff that means nothing to me.

maybe others have run your code and are having the same problem:
i.e. what's it supposed to do if there is a comment line

good chance you'd get a solution if you posted modified code that deals with just
comment lines - avoiding all the other stuff printed out.
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

Hello Michael,

Thanks a lot for the reply, I really appreciate it. However, I managed to solve this issue (of course with a small bug ). Thanks a lot again.

Marking this thread as solved
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextPane: Identifying Comment Lines