Trouble using read() to append html text to JEditoPane()

Trouble using read() to append html text to JEditoPane()
I`ve created the method bellow in my GEditorPane class, wich extends JEditorPane. The problem is that, after each appended text, an undesired line break is added. I checked the getText() of the pane, and there was no <br> (but a \n) where the line breaks are localized, what is strange, since html doesn`t break lines with \n.
Someone can help me ? Thankyou. SrLontra
public void append(String str) {
try {
Document doc = getDocument();
if (str == null || str.equals("")) {
return;
Reader r = new StringReader(str);
HTMLEditorKit kit = (HTMLEditorKit) getEditorKit();
kit.read(r, doc, doc.getLength());
} catch (IOException ioe) {
UIManager.getLookAndFeel().provideErrorFeedback(this);
System.out.println("IOException :: appendHTML() :: GEditorPane");
System.out.println(ioe.getMessage());
} catch (BadLocationException ble) {
UIManager.getLookAndFeel().provideErrorFeedback(this);
System.out.println(     "BadLocationException :: appendHTML () :: GEditorPane");
System.out.println(ble.getMessage());
}

Hello lukik,
This is not exactly my problem, in my case, the break is not desired. For some reason, just before the appended text, a line break (\n) is inserted in the Document. And I don`t want this to happen. Added to this, why the HTML text breaks with the \n?
Anyway, the threads were very instructive ^^.
Thankyou. SrLontra.

Similar Messages

  • HtmlDocument.insertString() no render html text :-(

    I have a chat pane that is a jtextpane.
    When a user writes into the chat i use document.insertString to append the user text.
    This works ok.
    But now, i want to add hyperlinks to the chat pane, so a user could double-click on them and browse on internet.
    So i set a HTMLEditorKit in the textPane.
    When a user writes into the chat i use document.insertString to append the user text....
    But if the text is html, like < html>< b>hello</b></html>
    In the chat pane appends exactly the same: < html>< b>hello</b></html>
    If i want to display the rendered html text i have to execute:
    chatPane.setText(chatPane.getDocument().getText(0,chatPane.getDocument().getLength())); <-- this works ok
    But this solution is more expensive if the text grows. And it is a chat, the text always grows!
    Is there another solution to append html text (and render it) into a jtextpane or jeditorpane ???
    Can i create hyperlinks without the htmleditorkit?
    Thanks in advance.
    jcpa1

    I executed doc.insertString(0,"text",null);
    null is the AttributeSet. But i dont know which attribute set i have to use.
    Please a little help :-(

  • Sorry about first try : how to avoid html-text tag converting & to & amp;

    subject
    how to avoid html:text tag converting "&" to "& amp;"?
    body
    hi,
    i have some values on DB like "& #351;" and when i use html:text to
    show binding's value, html:text converts "&" to "& amp;". in generated
    html, it looks like "& amp;#351;".
    how to avoid this conversion?
    thanks...
    Ayhan G�ng�r
    note: i use white-space among special characters because browser renders them. ex : (& amp; to &)

    hi, i use property attribute of html:text.
    property is declared in UIModel xml file.
    i mean, i don't use something like
    <html:text value="data"/>i use just like
    <html:text property="bindingName"/>and value is shown in generated html input tag as value.
    html:text has no attribute like filter.
    i think i should override html:text tag, and create a new tag that checks if value includes "& #351;" this type data. If there is, don't convert "&" to "& amp;"?
    any suggestions?
    thanks...
    Ayhan

  • How to append html formatted text to JPaneText?

    Hi,
    I'm trying to append html to JPaneText and I can't do it. My code is below:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.html.*;
    import javax.swing.text.*;
    public
    class GUI
    extends JFrame {
         JTextPane wynikTxtAre = new JTextPane();
         JScrollPane suwak = new JScrollPane(wynikTxtAre);
         JPanel panelSrodek = new JPanel();
         HTMLDocument doc;
         HTMLEditorKit kit = new HTMLEditorKit();
         public GUI()
    super.setSize(640, 480);
    super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    wynikTxtAre.setEditable(false);
    wynikTxtAre.setDocument(kit.createDefaultDocument());
    doc = (HTMLDocument)wynikTxtAre.getDocument();
    suwak.setPreferredSize(new Dimension(600, 400));
    panelSrodek.add(suwak);
    super.getContentPane().setLayout(new BorderLayout());
    super.getContentPane().add("Center", panelSrodek);
    super.setVisible(true);     
         public static void main (String [] args) {
              GUI g = new GUI();
              try {
         Style style = g.doc.addStyle("StyleName", null);
         StyleConstants.setItalic(style, true);
         StyleConstants.setFontSize(style, 30);
         StyleConstants.setBackground(style, Color.blue);
         StyleConstants.setForeground(style, Color.white);
         // Append to document
         g.kit.insertHTML(g.doc, g.doc.getLength(), "tekxt", 1, 1, HTML.Tag.B);
         //g.doc.insertString(g.doc.getLength(), "<b>Some Text</b>", style);
         } catch (Exception e) {
              System.out.println(e.getMessage());
    If i use insertHTML method then there is no text on the text area.
    If i use insertString method then text appear but it doesn't resolve html tags.
    Please help.

    I did something like this:
    public
    class GUI
    extends JFrame {
    //previous code - no changes
         public static void main (String [] args) {
              GUI g = new GUI();
              StringBuffer buf = new StringBuffer();
              try {
         buf.append("<b>bb</b>");
         buf.append("<b>ccc</b>");
         // First append to document
         g.pane.setText(buf.toString());
    //Second append
         buf.append("<b>ddddd</b>");
         g.pane.setText(buf.toString());
         } catch (Exception e) {
              System.out.println(e.getMessage());
    I know that this method is not smart and doesn't look good, but it works.
    If you know how to append html using HTMLEditorKit and HTMLDocument please write some example.

  • Open hyperlinks in html text using StageWebView instead of external browser

    My iPad app downloads xml data from a server and displays it as html text. The text may contain hyperlinks and currently these are correctly displayed as links in my app. However when I click on the link, it opens the link in an external browser.
    Any idea how I could instead open the links using StageWebView - I know how to open a link using StageWebView - the problem is intercepting whatever causes it to open in the external browser and instead use StageWebView.
    Thanks in advance

    Hi, John, welcome to Apple's user-to-user discussion forums.
    Does anyone here know of a way to open new windows without using command click in a tab?
    If you want links on a web page to open in a new tab, you need to command-click on them. This will work both for links set up to open in the same window and those set up to open in a new window. There is no setting in Preferences to make links on a web page automatically open in a new tab.
    There is a preference setting to open links from other programs, such as Mail, in a new tab. In Safari's Preferences, click on the General icon. Towards the bottom where it says "Open links from applications", check "in a new tab in the current window".

  • Can text be formatted when using 'Append report text.vi'?

    The example that ships with LabVIEW 7 'Generate Report from Template (Word).vi' uses 'Append report text' to insert text into a word template via bookmarks.
    My question is can this text be formatted in any way (e.g. fontsize, fontcolor, ...)? It seems I can't format the bookmark and I can't format the transmitted text. It always appears in Normal Arial 12pt.
    Thanks!

    Thank you,
    this works well for formatting the whole report. I also found that the Word Format Text.vi placed directly behind the Append Report Text.vi changes the attributes for the previously inserted text at the bookmark.

  • Use jbo:InputRender instead of html:text

    I'm currently trying JDev 10g preview and i'm using Business Components with Struts. When i use the data control palette to create an input form in a JSP page, all the input are html:text. Is there a way to set the default type of all inputs to jbo:InputRender instead of html:text?
    Thanks
    J�r�

    No, i would like to set the type of each input in my Business Component instead of in the JSP pages. This way, if i want to change the type of an input, i will have to change my business component, not my JSP pages.
    So, to be able to do this, i have to change every input from html:text to jbo:InputRender in all my forms. Which i think is not optional, because if the input type is not indicated, jbo:InputRender use the input type (which in most case, except for dates, is html:text).

  • Html text in label is moving when used as a renderer in a table cell

    Hi everybody,
    Because it is impossible to use gradient background for html, I created a custom TableCellRenderer that uses a JLabel (for the html text) inside a JPanel with a gradient background. (I use jdk1.5.0_06)
    However, in the code that I'm posting, something strange happens. The text is moving up and down as I move with the arrow button along the first row, from left to right and backwards, crossing the entire row.
    You can see for yourself. If someone can explain this behavior, please help!
    public class MyFrame extends javax.swing.JFrame {
        public static void main(String args[]) {
               new MyFrame().setVisible(true);
        public MyFrame() {
             setTitle("Use LEFT & RIGHT buttons to test");
            javax.swing.JTable table = new javax.swing.JTable();
            table.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] { {"", "", ""}, {"", "", ""}, {"", "", ""}, {"", "", ""}, {"", "", ""}, {"", "", ""} },
                new String []   { "Title 1", "Title 2", "Title 3" }
                public Class getColumnClass(int columnIndex) {
                    return String.class;
            table.setRowHeight(30);
            table.setRowHeight(0,100);
            table.setRowSelectionInterval(0,0);
            table.setColumnSelectionInterval(0,0);
            table.setValueAt("This text MOVES up-down as you move across THIS ROW!!!",0,0);
            table.setValueAt("This text MOVES up-down as you move across THIS ROW!!!",0,1);
            table.setValueAt("This text DOES NOT MOVE as you move across THIS ROW!!!",0,2);
            table.setDefaultRenderer(String.class,new StringRenderer());
            getContentPane().add(table, java.awt.BorderLayout.CENTER);
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setBounds(200,200,500,300);
        class StringRenderer extends GradientPanel implements javax.swing.table.TableCellRenderer {
            public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                   label.setText("<html><p align=center>"+String.valueOf(value)+"</p></html>");
                setColors(new java.awt.Color(255,255,255),isSelected?new java.awt.Color(255,100,100):new java.awt.Color(255,200,200));
                label.setBorder(hasFocus?new javax.swing.border.LineBorder(java.awt.Color.yellow,1):null);
                return this;
        class GradientPanel extends javax.swing.JPanel {
            private java.awt.Color c1,c2;
            protected javax.swing.JLabel label;
            public GradientPanel() {
                label = new javax.swing.JLabel();
                setLayout(new java.awt.GridBagLayout());
                java.awt.GridBagConstraints gbc = new java.awt.GridBagConstraints();
                gbc.fill = java.awt.GridBagConstraints.BOTH;
                gbc.weightx = 1.0;
                gbc.weighty = 1.0;
                gbc.insets = new java.awt.Insets(5,5,5,5);
                add(label, gbc);
            public void setColors(java.awt.Color c1, java.awt.Color c2) {
                this.c1 = c1;
                this.c2 = c2;
                this.repaint();
            public void paintComponent(java.awt.Graphics g) {
                if ( c1 != null && c2 != null ) {
                    java.awt.Graphics2D g2d = (java.awt.Graphics2D)g;
                    g2d.setPaint(new java.awt.GradientPaint(0,0,c2,0,this.getHeight(),c1,false));
                    g2d.fillRect(0,0,this.getWidth(),this.getHeight());
    }

    If someone can explain this behavior, please help!Can't explaing the behavour, but it seems to work fine when you use a JeditorPane or JTextPane which are specifically designed to display HTML.

  • Render HTML text as read-only field

    Hi,
    I want to display the text entered in a rich text editor as "true" HTML in read-only mode. If I make the field read-only (Read Only = Always), the display is screwed up quite badly. Obviously CSS gets in the way somehow.
    Here's how to see my problem:
    - create a report/form with a text field (e.g. a CLOB, but that doesn't matter), displayed as "Rich Text Editor", and enter some text.
    - create the same report/form again, this time making the field read-only.
    Quite a difference...
    Has anybody a quick answer?
    Thank you,
    Thomas

    Hi,
    yeah, that would be ok. I tried it already, but if I use something like "&P8_HTML.", the HTML text is displayed and not rendered.
    But I followed this up again after reading your advice, and I found that if I enter true HTML code as the region source, it's rendered as expected. The rest was simple:
    - create a separate region for the HTML display (as you proposed).
    - make the region type "PL/SQL (anonymous block)".
    - use "BEGIN \n htp.print(:P8_HTML); \nEND;" as region source.
    Thank you all very much for this instantaneous help!
    Cheers,
    Thomas

  • Using get -childitem to scan different drives but append one text file.

    Folks,
    I need some help, I wrote the below to scan for certain files types on client machines but I cant get the script to scan anything other than the C$. Apologies I am kind of new to scripting and PS. The script is kicked off using a batch file that makes the
    CR directory on the clients. I think the problem stems from the $disk variable or the way I have used foreach or the loop - any help would be appreciated
    Set-Location c:\
    $s = new-object -comObject SAPI.SPVoice
    $s.speak("Scan in progress")
    write-host "Scanning for files"
    $Extension = @("*.zip","*.rar","*.ppt","*.pdf")
    $Path = "$env:userprofile\Desktop"
    $disks = "c$","D$"
    foreach ($disks in $disks)
    {get-childitem -force -include $Extension -recurs -EA SilentlyContinue >$path\files.txt}
    $s.speak("Scan completed")
    Write-Host "Scan complete, files.txt created on your desktop - press any key to exit..."
    $x = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp")
    Remove-Item c:\cr -recurse -EA SilentlyContinue
    exit

    Then there is "$x = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp")" , What are you trying to do?
    It looks like that is a pause after the code has completed to give the user time to read the message prior to exiting.
    @V Sharma - As gaff-jakobs has mentioned, there are some parts of your code that need looked at. Please take a look at what he has advised and make the necessary changes. If you want to append data (doing a > does not append), I would look at using Out-File
    -Append -FilePath <filename> to accomplish this. 
    Usually, outputting to a text file limits what you can do with the output once it goes to a text file. I would look at using something such as Export-Csv -Append -Path instead (assuming you are running PowerShell V3). But if saving to a text file is part
    of your requirement, then just be sure to use the first method I mentioned.
    Boe Prox
    Blog |
    Twitter
    PoshWSUS |
    PoshPAIG | PoshChat |
    PoshEventUI
    PowerShell Deep Dives Book

  • html:text styleid problem while using document.getElementById -very urgent

    Hi all,
    I am using the following struts code in my jsp.
    Each time when I click the checkbox corresponding to each record, I want the screencode to be displayed using the javascript alert.
    But always I am getting the same screencode (only the first screencode).
    What I should do to get the screencode for the corresponding selection of the checkbox
    <logic:iterate id="slist" name="scrlist" scope="session" >
    <html:text property="screencode" name="slist" styleId="sc" indexed="true"/>
    <bean:write name="slist" property="screen"/>
    <html:checkbox property="readchk" alt="Select to enable read right" onclick="javascript:alert(document.getElementById('sc').value)"/>
    </logic:iterate>
    Could anybody help me to fix this problem as soon as possible
    parvathy

    The tricky thing about Ajax is that it's asynchronous. That's the point...
    What you need to do is return a success or fail status from your servlet (or whatever ServiceAuth is...), let's say a 1 or 0. (0 bad, 1 good). You could even get real fancy and return 0 for username doesn't exist, 1 for password doesn't match user name or 2 for success.
    Then have your javascript update the page based on the response received. On a fail response call some javascript method that displays your related Uh-oh message, and on a successresponse call some method that updates the document.location of the page.
    HTH.

  • Can you use html text in flash cc html5 project type?

    I'm attempting to dynamically change font color of various words inside a dynamic text field.
    I have tried both these lines of code below. have you dont this can you correct my code please?
    I'm using flash cc and html5 project type. This was possible in previous versions of flash.
    this.Logger.Log_File.htmlText = "<font color='#000000' size='-1'>"+MyGreatNumber+" "+"</font><BR>"+this.Logger.Log_File.htmlText;
    this.Logger.Log_File.htmlText = "<p style="color:#ff0000">"+MyGreatNumber+"</p><br>"+this.Logger.Log_File.htmlText;

    from the easeljs docs: Please note that Text does not support HTML text, and can only display one font style at a time. To use multiple font styles, you will need to create multiple text instances, and position them manually.
    to resolve, edit text in the js file where it's relatively easy to even use rtl text.

  • Having trouble figuring out how to forward text messages.  Can someone tell me how to do that?  Where the forward button.  You used to be able to hit forward and put radio button on all the messages.  The screen looks blank to me.

    In the new iOS7, Having trouble figuring out how to forward text messages.  Can someone tell me how to do that?  Where the forward button.  You used to be able to hit forward and put radio button on all the messages.  The screen looks blank to me.

    In the new iOS7, Having trouble figuring out how to forward text messages.  Can someone tell me how to do that?  Where the forward button.  You used to be able to hit forward and put radio button on all the messages.  The screen looks blank to me.

  • Need to compare html text area values by using java script

    I have one html text area in my JSP file. when i click on that text area, a pop-up will come, in that pop-up i have list of items. So after selecting a item from that pop-up list, need to click okay. so that text area will update with the selected value.
    In this case, i need to compare the first text area value and updated text area value. How can i do that in Java Script.

    I suggest you look for a Javascript forum to ask questions about Javascript. This is a Java forum.

  • I'm having trouble using Adobe Reader

    I'm having trouble using or uninstalling Adobe Reader, i get a message when the programme has been anitiated which says Adobe Reader has encountered a problem and needs to close, i went on to Adobe's website and it said try uninstalling Adobe Reader and then re-install it as this sometimes works, i tried un-installing it from the Add or Remove programme but that didn't work either as i got another message telling me that the patch package could not be verified and to make sure i have permission.

    Dear Mylenium.
    Sorry i don't quite understand your reply, What do you need to know?

Maybe you are looking for

  • My new iMac iTunes won't recognize my old apple id like my pc and iPad do

    Trying to setup iTunes on my new refurb iMac.  I have an apple id that is so old it isn't even an email both my pc and iPad are setup with a new apple Id the sales rep setup and it recognized my old Id in iTunes with all my purchases and money but, m

  • How to install KDE and Gnome

    Normally I'm a big KDE user, but there are some things in GNOME I want to try out to see if I might make the switch. I already have KDE installed, if I wanted the option to run KDE or GNOME can I just 'sudo pacman -S gnome gnome-extras' and it'll sho

  • How do I transfer data (music, photos, contacts) from iphone to ipad?

    I just bought an ipad2 and I am now trying to get all my photos and music from my iphone to my new ipad.

  • How to use responseXML to parse xml

    Hi, I am sending this xml from server <assignmentList> <assignment> <id>333</id><name>1170235257994</name><fileClass>4</fileClass><checked_out_by> </checked_out_by><status>s1</status><publication>p1</publication><section>s1</section><change_type>1</c

  • Too many responses (!)

    I recently posted two questions in the forum, later I received over 100 replies (about 105 I think) in my e-mail, most of which were not related to my question. I don't know if I did something wrong, checked something I shouldn't have or what - I am