?
Solved

jEditorPane

Posted on 2005-03-21
8
Medium Priority
?
1,640 Views
Last Modified: 2008-01-09
I have a really small, but really annoying problem.  I have a jEditorPane, and I want to be able to repeatedly add text to it (like a lot), so I figured

ePane.setText(ePane.getText() + str);

would evetually get so much text that an exception would get raised with ePane.getText() + str

So with the help of you guys, I now have the following:

In the constructor:

myEditorPane.setDocument(new HTMLEditorKit().createDefaultDocument());

in the method where I append text:

        HTMLDocument doc = (HTMLDocument)myEditorPane.getDocument();
        Element bc = doc.getRootElements()[0].getElement(0).getElement(0);
        try{
            if ( -- first time we are adding text (I really have code to test this, it just wouldn't mean anything to you guys--  ){
               
                doc.insertString(0, "First line.", null);

                //doc.insertAfterStart(bc, s + "<br>");
                //myEditorPane.setText("<html><body></body></html>");
                //myEditorPane.setText(s + "<br");
                //doc.setInnerHTML(bc, "<html><body></body></html>");
                //doc.insertBeforeStart(bc, s);
                //doc.insertBeforeEnd(bc, "<b>hi there</b>");
                               
                //doc.insertBeforeEnd(bc, "First Line.");
            }
            else
                doc.insertBeforeEnd(bc, s + "<br>");            
            //doc.insertString(doc.getLength(), s, null);
        } catch(Exception e){
            System.out.println("Exception " + e);
        }

OK.  Here is the problem.  The FIRST time I call this method, there is a newline above where the text is.  In other words, it is putting the text on the second line (the first time I call this method).  You can see all the things I have tried getting this to work right.  I was originally using a jTextArea, but apparently you can't (or it's really hard) to put HTML in there.  I have also tried each of these options WITHOUT what is in the constructor.
0
Comment
Question by:ARACK04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13598582
could just be the html margin, try setting your margins to zero.
0
 
LVL 5

Expert Comment

by:Naeemg
ID: 13599104
r u really concerning to put or append text in particular tag?
Or just append text in previous?
0
 

Author Comment

by:ARACK04
ID: 13600522
just append text to previous.  jTextArea makes it super easy, but I also want to add color, which is why I switched to jEditorPane.  Anyway, I don't care how, just append text to previous.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:ARACK04
ID: 13602570
I am willing to take a work around.  Is there any way to specify the color of the text you append to a jTextArea?
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 13608630
>  jTextArea makes it super easy, but I also want to add color, which is why I switched to jEditorPane.

JEditorPane is not needed if you want to add colour.
JTextPane supports styled text.
0
 
LVL 5

Expert Comment

by:Naeemg
ID: 13608792
still you can use JEditorpane.

try this.

suppose  following is ur data String .

String data ="your data";
char QUOTE = '\"'; // double quote

set the following type of editorpane as html after the Jeditor pane first time u make its empty constructor

jeditor.setContentType("text/html");

now add the following lines when u want to append text.

String font = "<br><font color=" + QUOTE +
               "#F99Fcc" + QUOTE + "><b>" + data + "</b>&nbsp;&nbsp;</font>";

jeditor.setText(jeditor.getTex() + font);

/// try it i hope it will work for u.
0
 

Author Comment

by:ARACK04
ID: 13609096
I think the point of this question has become blurred.  A new one is here:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21361312.html

I'll give credit for both if anyone can give me a solution for it.
0
 

Author Comment

by:ARACK04
ID: 13612187
Question has been solved on new question.  Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

752 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