Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1647
  • Last Modified:

jEditorPane

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
ARACK04
Asked:
ARACK04
  • 4
  • 2
  • 2
1 Solution
 
objectsCommented:
could just be the html margin, try setting your margins to zero.
0
 
NaeemgCommented:
r u really concerning to put or append text in particular tag?
Or just append text in previous?
0
 
ARACK04Author Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ARACK04Author Commented:
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
 
objectsCommented:
>  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
 
NaeemgCommented:
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
 
ARACK04Author Commented:
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
 
ARACK04Author Commented:
Question has been solved on new question.  Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now