JTextPane and HTML form

I'd like to display html page containing simple HTML form. JTectPane renders tis form very good but i sthere any way to handle any data change/submit on such a form in JTextPane

Hi,
Take a look at this example
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class TestShowPage {
public static void main(String args[]) { 
JTextPane tp = new JTextPane();
JScrollPane js = new JScrollPane();
js.getViewport().add(tp);
JFrame jf = new JFrame();
jf.getContentPane().add(js);
jf.pack();
jf.setSize(400,500);
jf.setVisible(true);
try {
URL url = new URL("http://www.globalleafs.com/Download.html" );
tp.setPage(url);
catch (Exception e) {
e.printStackTrace();
Just compile and run the programme. see the output. If you need more info of such type of programmes, check http://www.globalleafs.com/Download.html
Uma
Java Developer
http://www.globalleafs.com

Similar Messages

  • JSP and HTML forms

    Hi, I have been trying to work out a way to label rows of a dynamic html form, which can then be referenced by jsp. The project is a uni one in which we are building an online book store. At the moment, we have made a search for out database, the resultant table's size is obviously done on how many results there are. ONce the results are up, for every book, there is a text box, the name of which is the ISBN of that particular book (unique code every book has, thus the primary key). This text box is going to be used so that the 'customers' can enter in a number, which will be how many copies of this book they want.
    This jsp files needs to be referenced by another, so we can send a cookie to the user's computer with book details. unfortunately, in order to know which book, and how many, the user wants, we need to know the name of the check box from the first jsp file, which we cannot hardcode because due to the dynamic nature of the form will be different every time!
    Are we going about things the wrong way, because I cant seem to work out a way to do this.
    Thanks,
    Alex

    Regardless of how many results are returned, the name of your checkbox will always be the same... that's just the nature of a list of checkboxes. What changes is the values of each individual checkbox, which can be retrieved using
    String[] booksChecked = request.getParameterValues("books")where "books" is the name of your checkbox.
    If each book has a unique ID, then probably use this value as the value of the checkbox, and then you receive an array of IDs.
    To dynamically handle the quantity boxes, name each textbox with the unique key plus an extra bit of text..
    <input type="text" name="<%= book.ID%>qty">
    Then you can retrieve the quantity for each book by using..
    for(int i=0; i < booksChecked.length; i++)
      String qty = request.getParameter(booksChecked[i]+"qty");
    }Hope this is what you're looking for :)

  • Flash navigation and HTML forms

    Wondering if any one can help. Whenever I use an html form on
    an html page, my flash navigation will not show up. The area where
    it should be is blank and my browser status bar says that there are
    two items remaining (my flash navs). The browser stays like this
    indefinately, not completely loading the page.
    Any suggestions ?
    Thanks,
    Elise

    Thank you for reply. I appreciate it. So, if I understand
    correctly:
    I would embed the navbar.swf in all my html files. Then Each
    button would go to each html pages (Like page1.htm page2.htm
    etc...) Then I use your code in my html file right? Like each html
    file will have the following code:
    <param name="movie" value="nav.swf?frame=page2">
    Is that how it works. Sorry for not being able to your
    answer.
    Thank you very much again

  • TableCellRenderer with JTextPane and HTML

    I'm writing a TableCellRenderer that will be rendering HTML content using a custom extension to the JTextPane class. Where I'm having trouble is in calculating the necessary height to set the table row based on the content of the cell (in this case HTML text in my JTextPane component). I know the width of the table cell and I can figure out the width of the content (taking into account the formatting because of the HTML content). This all works perfectly until the column width shrinks enough to cause the underlying view to word wrap.
    Here is the code snippet from my JTextPane to count the number of lines of text and calculate the width of the content
      public int getWidthOfContent() {
        getLineCount();
        return m_iWidthOfContent;
      public int getWidthOfContent(int p_iWidthOfArea) {
        getLineCount(p_iWidthOfArea);
        return m_iWidthOfContent;
      public int getLineCount(int iComponentWidth) {
        int iWidth = 0;
        int iBreakCount = 0;
        int iHardBreakCount = 0;
        int iTotalWidth = 0;
        int iTotalContentWidth = 0;
        int iMaxHeight = 0;
        Document doc = getDocument();
        ElementIterator it = new ElementIterator(doc.getDefaultRootElement());
        StyleSheet styleSheet = null;
        if(doc instanceof HTMLDocument) {
          styleSheet = ((HTMLDocument)doc).getStyleSheet();
        if(iComponentWidth == -1) {
          iWidth = getWidth();
        else {
          iWidth = iComponentWidth;
        Element e;
        while ((e=it.next()) != null) {
          AttributeSet attributes = e.getAttributes();
          Enumeration enumeration = attributes.getAttributeNames();
          boolean bBreakDetected = false;
          while(enumeration.hasMoreElements()) {
            Object objName = enumeration.nextElement();
            Object objAttr = attributes.getAttribute(objName);
            if(objAttr instanceof HTML.Tag) {
              HTML.Tag tag = (HTML.Tag)objAttr;
    //          if(tag == HTML.Tag.BODY) {
    //            UCSParagraphView pv = new UCSParagraphView(e);
    //            if(pv.willWidthBreakView(iWidth)) {
    //              iHardBreakCount++;
              FontMetrics fontMetrics = null;
              if(styleSheet != null && styleSheet.getFont(attributes) != null) {
                fontMetrics = getFontMetrics(styleSheet.getFont(attributes));
              if(fontMetrics != null && fontMetrics.getHeight() > iMaxHeight) {
                iMaxHeight = fontMetrics.getHeight();
              if(tag.breaksFlow()) {
                //This must be a breaking tag....this will add another line to the count
                bBreakDetected = true;
                if(tag.equals(HTML.Tag.BR) || tag.isBlock() && (!tag.equals(HTML.Tag.HEAD) && !tag.equals(HTML.Tag.BODY))) {
                  if(iTotalContentWidth == 0) {
                    iTotalContentWidth = iTotalWidth;
                    iTotalWidth = 0;
                  else if(iTotalWidth > iTotalContentWidth) {
                    iTotalContentWidth = iTotalWidth;
                    iTotalWidth = 0;
                  else {
                    iTotalWidth = 0;
                  if(tag.equals(HTML.Tag.H1) || tag.equals(HTML.Tag.H2) || tag.equals(HTML.Tag.H3) || tag.equals(HTML.Tag.H4)) {
                    iHardBreakCount += 3; //These count as three lines (Blank - Content - Blank)
                  else {
                    iHardBreakCount++;
                iBreakCount++;
          if(!bBreakDetected) {
            Font font;
            FontMetrics fontMetrics;
            if(e.getDocument() instanceof HTMLDocument) {
              font = ((HTMLDocument)e.getDocument()).getStyleSheet().getFont(e.getAttributes());
              fontMetrics = getFontMetrics(font);
            else {
              font = getFont();
              fontMetrics = getFontMetrics(font);
            int iRangeStart = e.getStartOffset();
            int iRangeEnd = e.getEndOffset();
            if(fontMetrics.getHeight() > iMaxHeight) {
              iMaxHeight = fontMetrics.getHeight();
            if(e.isLeaf()) {
              String strText;
              try {
                strText = this.getText(iRangeStart, iRangeEnd - iRangeStart);
                if(strText.equals("\n")) {
                  //iBreakCount++;
                iTotalWidth += SwingUtilities.computeStringWidth(fontMetrics, strText);
              catch (BadLocationException ex) {
                //Something happened.....don't care....just eat the exception
        m_iMaxFontHeight = iMaxHeight;
        m_iWidthOfContent = iTotalWidth;
        m_iHardBreakCount = iHardBreakCount;
        if(iWidth > 0) {
          int iLineCount = (iTotalWidth / iWidth) + iBreakCount;
          return iLineCount;
        return 1;
      }And here is the code from my TableCellRenderer that uses the above information
       public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                                                      boolean hasFocus, int row, int column) {
         if(ValidationHelper.hasText(value) && value.toString().indexOf("<html>") != -1) {
           UCSHTMLTextPane pane = new UCSHTMLTextPane();
           pane.setText(ValidationHelper.getTrimmedText(value.toString()));
           BigDecimal lWidthCell = new BigDecimal(table.getCellRect(row, column, false).getWidth() - 15);
           BigDecimal lWidthContent = new BigDecimal(pane.getWidthOfContent(lWidthCell.intValue()));
           int iHardBreakCount = pane.getHardBreakCount();
           BigDecimal lLineCount = lWidthContent.divide(lWidthCell, BigDecimal.ROUND_CEILING);
           int iLineCount = lLineCount.intValue();
           double dWidthCell = lWidthCell.doubleValue();
           double dWidthContent = lWidthContent.doubleValue();
           double dWidthContentPlusFivePercent = dWidthContent + (dWidthContent * .01);
           double dWidthContentMinumFivePercent = dWidthContent - (dWidthContent * .01);
           if(dWidthCell >= dWidthContentMinumFivePercent && dWidthCell <= dWidthContentPlusFivePercent) {
             iLineCount++;
           iLineCount += iHardBreakCount;
           int iMaxFontHeight = pane.getMaxFontHeight();
           int iHeight = (iMaxFontHeight * iLineCount) + 5;
           if ( (iLineCount > 0) && (table.getRowHeight(row) != iHeight)) {
             pane.setPreferredSize(new Dimension(0, iHeight));
             if(m_bAutoAdjustHeight) {
               table.setRowHeight(row, iHeight);
           if(iLineCount == 1) {
             if(iHeight != table.getRowHeight()) {
               if(m_bAutoAdjustHeight) {
                 table.setRowHeight(iHeight);
           setComponentUI(pane, table, row, column, isSelected, hasFocus);
           return pane;
    }Any suggestions?

    Hello,
    You must initialize correctly your JTextPane like this:
    javax.swing.text.html.HTMLEditorKit htmlEditorKit = new javax.swing.text.html.HTMLEditorKit();
    javax.swing.text.html.HTMLDocument htmlDoc = (javax.swing.text.html.HTMLDocument)htmlEditorKit.createDefaultDocument();
    setEditorKit(htmlEditorKit);
    setDocument(htmlDoc);
    setEditable(true);
    setContentType("text/html");

  • JTextPane and HTML rendering

    HAi
    I have a web page with JApplet in it.
    I need to get a HTML page from server and display it. I wish to use either JEditorPane or JTextPane.
    The applet gets the file line by line from the server. I need to append the line by line to the component.
    (i need to do some mappings before displaying, thats why i need to get text in parts.)
    I tried to append line by line to JTextPane. But Pane is treating as text file. The tags are not getting recognised. Instead whole of the file is being displayed along with tags.
    Is there any way by which i can append the file line by line with the tags being interpreted as they should be.
    Anticipating an early reply
    With thanks and regards
    Maruti

    Hello,
    You must initialize correctly your JTextPane like this:
    javax.swing.text.html.HTMLEditorKit htmlEditorKit = new javax.swing.text.html.HTMLEditorKit();
    javax.swing.text.html.HTMLDocument htmlDoc = (javax.swing.text.html.HTMLDocument)htmlEditorKit.createDefaultDocument();
    setEditorKit(htmlEditorKit);
    setDocument(htmlDoc);
    setEditable(true);
    setContentType("text/html");

  • JTextPane and HTML

    My pane is continuing to display the text as plain text instead of html. Why is that?
    JTextPane p=new JTextPane(new HTMLDocument());
    add(p);
    String html="<html><body>TEST</body></html>
    p.setText(html);From what I've learned from the documentation, the pane is initialised with html. When using setText(), the pane still keeps it html style. So, why am I getting plain text???

    If I explicitly use setContentType("text/html") it works.
    But it only works for small html pages. If I use a setText for a page greater than 50k, the page is blank. After that, a getText() results in this:
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>
    Is there a maximum?

  • Character Encoding for JSPs and HTML forms

    After having read loads of postings on character encoding problems I'm still puzzled about the following problem:
    I have an instance (A) of WL 8.1 SP3 on a WinXP machine and another instance (B) of WL 8.1 without any SP on a Win2K machine. The underlying Windows locale is english(US) in both cases.
    The same application deployed as a war file to these instances does not behave in the same way when it comes to displaying non-Latin1-characters like the Euro symbol: Whereas (A) shows and accepts these characters as request-parameters, (B) does not.
    Since the war file is the same (weblogic.xml, jsps and everything), the reason for this must either be the service-pack-level or some other configuration setting I overlooked.
    Any hints are appreciated!

    Try this:
    Prefrences -> Content -> Fonts & Color -> Advanced
    At the bottom, choose your Encoding.

  • Urgent :post xml for xsql difference with html form post

    Hi,
    We are developing an application to process xml request
    posted by external party. The requests arrive by
    http-post operation
    We developed and tested with an html-form.
    Now we encounter problems in testing with http-post
    The xsql page is processed correctly but
    insert only fixed text when formatting xml-data as input for
    the insert-request, string inserted is empty.
    Everything is by the book and html-forms works great.
    Is anybody else using xsql to insert xml data in the database on this version? Maybe can you help by looking into a testcase ? Issued a tar but am on terrible deadline
    so need help very soon.
    Details: HP-UX 11.11 Oracle 9.2.0.4 java1.4 ojdbc 1.4
    Tnx in advance,
    Jeroen

    Mark,
    Have an external partner which sends xml-requests.
    Have to read those, store them and process them.
    Idea is let them
    1)post the xml at a url where an xsql page is reading the xml
    2) transforming this for an insert into
    the database. The column is defined to store the complete xml-message.
    3) A trigger takes care of processing the stuff and preparing the output
    4) and a query in the xsql-page reads the output from an output table
    When developing and testing this with an html-form that posts the xml is works great.
    $ cat newclobins.xsql
    <?xml version="1.0"?>
    <page connection="demo" xmlns:xsql="urn:oracle-xsql" >
    <xsql:set-session-param name="id">
    select msgid.nextval from dual
    </xsql:set-session-param>
    <xsql:dml>
    delete cbs_msg_in where id={@id}
    </xsql:dml>
    <xsql:insert-request table="cbs_msg_in" column="id,msg" transform="cbsform_1.xsl"/>
    <data>
    <xsql:query null-indicator="yes">
    select msgid,msg from cbs_xml_out where msgid={@id}
    </xsql:query>
    </data>
    </page>
    $ cat cbsform_1.xsl
    <?xml version="1.0"?>
    <ROWSET xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">
    <xsl:for-each select="request">
    <ROW>
    <MSG><xsl:value-of select="parameters/doc" /></MSG>
    <ID><xsl:value-of select="session/id" /></ID>
    </ROW>
    </xsl:for-each>
    </ROWSET>
    1) When using a tool like
    http://www.programmersheaven.com/articles/adrian/getpost/article.html it fails with
    No rows to modify -- the row enclosing tag missing. Specify the correct row enclosing tag.
    2) When using the commandline utility like
    xsql jeroen5.xsql posted-xml=test3.xml
    this works great when inserting plain text but not
    when inserting xml-format data into a column
    So problem 1 is why external tools like above or my partner that uses .net to do something similar gives this strange error?
    Problem nr 2 is should I stick to just the data in xml and forget about storing the xml-formatted data?
    Hope you can help because I am getting quite desparate here.
    Regards,
    Jeroen

  • Converting HTML Forms to PDF - Field Names

    When I use Adobe 8 to convert and HTML form to PDF all the field names in the resulting PDF have the crazy long names that are jumble of letters and numbers. So I always have to go back through and manually rename every field because I'm using another program to autopopulate the fields with data. Is there any way to get Acrobat to automatically name the fields in the PDF the same as they are named in the form either using the "name" or "id" properties of the HTML fields? I don't understand why this isn't the default behaviour to begin with.

    The reason this is done is due to a fundamental difference between HTML forms and Acrobat forms. In HTML forms, fields with the same name do not necessarily share the same value, whereas in Acrobat forms they do.
    In the conversion process, Acrobat gives each field a unique name, but also sets a field's mapping name to the name the field had in the original HTML form. This is so that if the PDF form is used to submit as "HTML", then the original field names will be used and any server process that is capable of dealing with the HTML form is capable of dealing with the resulting PDF form. So be aware that if you want to use your modified form to submit to a web server using the "HTML" format, the new field names that you set will not be used. What will be used are the hidden mapping names.
    Unfortunately, I don't think there's anything you can do about any of this to make it work like you want.
    George

  • Problem in opening 'Find Service Request' and 'Create Service Request' HTML forms

    Hi,
    I  am working on creating some date for EBS Service, and I am unable to open 'Find Service Request' and 'Create Service Request' HTML forms.
    I keep getting the error message :
    Oracle error - 20001: ORA-20001: APP-FND-02902: Multi-Org profile option is required. Please set either MO: Security Profile or MO: Operating Unit profile option. has been detected in MO_GLOBAL_INIT.
    I have min knowledge of EBS set up and configuration. We just use EBS as a source system for our ETLs.  Please suggest any workaround to get resolve the issue.
    Thanks,
    Kishore

    Navigate to System Administrator responsibility > Profile > System. Search for the profile MO: Operating Unit and under responsibility field, put in the responsibility name you are using for creating the service request, click OK and enter the desired operating unit value in the next window. It pulls up all operating units defined and you can chose the desired one.
    Thanks
    Shree

  • Loading images in a table and show this image in a html form

    Hi All,
    I'am a newbie in Oracle and PL/SQL.
    I need to load a image in a table and restrive this image and show it in a html form. I'd like to use a PL/SQL procedure.
    Thanks in advance for any suggestions.

    Hi,
    This forum is for Oracle9iAS Web Services discussion.
    I would recommend that you post your question to the 9iAS - General discussion forum.
    Regards,
    Tim

  • JavaScript and "pdk-html:form" Variables

    I am having a problem using javaScript with my "pdk-html:form" variables.
    Here is what the .jsp looks like:
    <SCRIPT type=text/javascript>
         function test() {
              alert("act = "+window.document.facListBean.act.value);
    </SCRIPT>
    <pdk-html:form name="facListBean" .......>
         <pdk-html:text property="act" />
    </pdk-html:form>
    The problem is that when the HTML is rendered the name of the form field "act" gets translated to "_piref584_1533941_584_1533923_1533923.act"
    Is there a simple way to handle this problem? Can someone suggest a workaround?
    Thanks,

    hi Matt,
    i've faced the same problem. The only solution i've found was that:
    cicle your form and get all the elements in it.
    var field1;
    var x=document.getElementById("myForm");
    for (var i=0;i<x.length;i++) {
    if(x.elements.name.indexOf('field1')) field1 = x.elements[i];
    []s,
    Felippe

  • Images in HTML forms and/or reports

    Hi,
    Apologies if a stupid question, but can you display a combination of data and image content in Portal HTML forms and/or reports? If so, how?
    This question assumes that the image in question is browser-supported (e.g. gif file), and the link to it is in the same database table as the data being reported (as a bfile data type).
    Alternatively, what if the image was actually directly stored in the database table as a BLOB data type?
    Help!
    Cheers, Jeff

    Hi Sharmila,
    Thanks for the info!
    Would this also work if the image wasn't a blob, but instead just stored on the filesystem (as a gif file), with the reference to it stored in the database as a bfile datatype?
    Thanks once again, Jeff
    Hi,
    You can build portal forms to upload images. You can use blob columns here. You can also have images in a report. This will be the SQL to query data from tables having intermedia data.
    Select a.empno,a.ename,a.mgr,a.sal,
    portal30.wwv_user_utilities.get_intermedia('EMP','EMP_AUDIO','AUDIO',a.rowid)
    the_audio, b.dname,b.loc,
    portal30.wwv_user_utilities.get_intermedia('DEPT','DEPT_PICTURE','IMAGE',b.rowid) the_picture
    from emp a, dept b
    where a.deptno = b.deptno
    The table should have the ordimage column type.
    Thanks,
    Sharmila

  • Very big problem with JSF about FORM and "id=" for HTML form's elements and

    I have discovered a very big problem with JSF about FORM and "id=" for HTML form's elements and java instruction "request.getParameterNames()".
    Suppose you have something like this, to render some datas form a Java Beans :
    <h:dataTable value="#{TablesDb2Bean.myDataDb2ListSelection}" var="current" border="2" width="50%" cellpadding="2" cellspacing="2" style="text-align: center">
    <h:column>
    <f:facet name="header">
    <h:outputText value="Name"/>
    </f:facet>
    <h:outputText id="nameTableDb2" value="#{current.db2_name_table}"/>
    </h:column>
    </h:dataTable>
    Everything works fine...
    Suppose you want to get the name/value pairs for id="nameTableDb2" and #{current.db2_name_table} to process them in a servlet. Here is the HTML generated :
    <td><span <span class="attribute-name">id=<span class="attribute-value">"j_id_jsp_1715189495_22:0:nameTableDb2">my-table-db2-xxxxx</span></td>
    You think you can use the java instructions :
    Enumeration NamesParam = request.getParameterNames();
    while (NomsParam.hasMoreElements()) {
    String NameParam = (String) NamesParam.nextElement();
    out.println("<h4>"++NameParam+ "+</h4>);
    YOU ARE WRONG : request.getParameterNames() wants the syntax *name="nameTableDb2" but JSF must use id="nameTableDb2" for "<h:outputText"... So, you can't process datas in a FORM generated with JSF in a Servlet ! Perhaps I have made an error, but really, I wonder which ?
    Edited by: ungars on Jul 18, 2010 12:43 AM
    Edited by: ungars on Jul 18, 2010 12:45 AM

    While I certainly appreciate ejb's helpful responses, this thread shows up a difference in perspective between how I read the forum and how others do. Author ejb is correct in advising you to stay inside JSF for form processing if form processing is what you want to do.
    However, I detect another aspect to this post which reminds me of something Marc Andreesen once said when he was trying to get Netscape off the ground: "there's no such thing as bad HTML."
    In this case, I interpret ungar's request as a new feature request. Can I phrase it like this?
    "Wouldn't it be nice if I could render my nice form with JSF but, in certain cases, when I REALLY know what I'm doing" just post out to a separate servlet? I know that in this case I'll be missing out on all the nice validation, conversion, l10n, i18n, ajax, portlet and other features provided by JSF".
    If this is the case, because it really misses the point of JSF, we don't allow it, but we do have an issue filed for it
    https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=127
    If you can't wait for it to be fixed, you could decorate the FormRenderer to fix what you want.
    I have an example in my JSF book that shows how to do this decoration. http://bit.ly/edburnsjsf2
    Ed

  • How to use html form actions and methods

    Hi, I want to make a quick contact page using Edge. I used the following code in my creationComplete but had no luck.  Any help?
    var na = sym.$( "email" );
    email.html( '<form action="send_mail.php" method="post"><input type="text" id="email" value="" />' );
    var button = sym.$( "btn" );
    button.html( '<input type="submit" value="Send" />' );

    My understanding from your question is that you would like to programmatically (using LabVIEW) send input to and click a button on an existing HTML website, is that right?
    If yes, then you can use ActiveX calls to embed a web browser into the front panel of your VI and then use its invoke node to input a text to a form or click a button. Another way is to use the lower-level TCP VIs in LabVIEW, but you need to understand HTTP protocols to successfully use this. See below examples to get started.
    ActiveX
    https://decibel.ni.com/content/docs/DOC-25396
    https://decibel.ni.com/content/docs/DOC-12454
    TCP VIs (HTTP)
    https://decibel.ni.com/content/docs/DOC-2230
    http://zone.ni.com/devzone/cda/epd/p/id/3153
    FYI, LabVIEW Internet Toolkit has been deprecated starting LabVIEW 2012, so it is not recommended to build a new application using that.
    Hope this helps.
    Regards,
    A. Yodha
    Applications Engineer | National Instruments
    Singapore (65) 6226 5886 | Malaysia (60) 3 7948 2000 | Thailand (66) 2 298 4800
    Philippines (63) 2 659 1722 | Vietnam (84) 8 3911 3150 | Indonesia (62) 21 2924 1911

Maybe you are looking for