?
Solved

Display Txt file with chosen lines highlighted

Posted on 2005-05-05
11
Medium Priority
?
241 Views
Last Modified: 2010-03-31
I've created a log file parser..
Once I've parsed the file I have certain properties which I wish to use to highlight certain lines.

For example I have a message which occurs on line 2,000  and line 2,666.. I wish to output the whole file in  a JTextPane (or WordPad if thats possible) with only line 2000 and 2666 highlighted in a different color...

Any Ideas?
Thnaks in advance
0
Comment
Question by:conorocallaghan
  • 5
  • 5
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13933959
Use a JEditorPane +html
0
 
LVL 92

Expert Comment

by:objects
ID: 13933961
0
 
LVL 92

Expert Comment

by:objects
ID: 13933965
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 13933972
And this shows you how to insert styled text
http://www.javaalmanac.com/egs/javax.swing.text/tp_StyledText.html
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 13933997
editorPane.setEditable(false);
editorPane.setContentType("test/html");
if (lineNumber == 2000 || lineNumber = 2666) {
      stringBuffer.append(line).append("<br>");
}
else {
      stringBuffer.append(<font color=\"red\">").append(line).append("</font>").append("<br>");
}
editorPane.setText(stringBuffer.toString());
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13934002
Typos:

>>editorPane.setContentType("test/html");

should be

editorPane.setContentType("text/html");

and

>>
if (lineNumber == 2000 || lineNumber = 2666) {
     stringBuffer.append(line).append("<br>");
}
>>

should be

if (lineNumber != 2000 || lineNumber != 2666) {
     stringBuffer.append(line).append("<br>");
}
0
 

Author Comment

by:conorocallaghan
ID: 13934004
That more Like it CEHJ, I think that was what I was looking for. Will give it a try now
0
 
LVL 92

Expert Comment

by:objects
ID: 13934026
styles save you having to mark up the text, put the following in your loop as you add the lines :)

if (lineNumber == 2000 || lineNumber = 2666) {
     doc.insertString(doc.getLength(), line, hilitestyle);
}
else {
     doc.insertString(doc.getLength(), line, plainstyle);
}
0
 
LVL 92

Expert Comment

by:objects
ID: 13934030
dealing with large files the performance would likely be a lot better to

and give you control over the style
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13934048
>> dealing with large files the performance would likely be a lot better to

I'd guess that exactly the reverse would be the case, but would reserve judgement pending testing ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13935270
:-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question