How to get document's length of JTextPane

Hi all,
I loaded the content of JTextPane by invoking setPage(URL url), but the length of the styledDocument is ZERO
textPane.setPage(new URL("http://www.google.com"));
StyledDocument doc = textPane.getStyledDocument();
System.out.println("doc.getLength(): " + doc.getLength());  // the result is: doc.getLength(): 0Could you tell me why and how to work around?
Any help is appreciated!
Thanks in advance.
Daniel.Sun

Try calling it after your Swing visible components have been rendered:
import java.awt.Dimension;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.StyledDocument;
public class DocumentLength
  private JPanel mainPanel = new JPanel();
  private JTextPane textPane = new JTextPane();
  public DocumentLength()
    JScrollPane scrollpane = new JScrollPane(textPane);
    scrollpane.setPreferredSize(new Dimension(500, 300));
    try
      textPane.setPage(new URL("http://www.google.com"));
    catch (MalformedURLException e)
      e.printStackTrace();
    catch (IOException e)
      e.printStackTrace();
    mainPanel.add(scrollpane);
    System.out.println("BEFORE RENDERING: doc.getLength() = " + getDocLength());
  public int getDocLength()
    StyledDocument doc = textPane.getStyledDocument();
    return doc.getLength();
  public JPanel getMainPanel()
    return mainPanel;
  private static void createAndShowUI()
    DocumentLength docLength = new DocumentLength();
    JFrame frame = new JFrame("Document Length");
    frame.getContentPane().add(docLength.getMainPanel());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    System.out.println("AFTER RENDERING: doc.getLength() = " + docLength.getDocLength());
  public static void main(String[] args)
    java.awt.EventQueue.invokeLater(new Runnable()
      public void run()
        createAndShowUI();
}

Similar Messages

  • How to get the bold texts in JTextPane?

    How to get the bold texts in JTextPane?

    I believe you need to look at the Elements of the Document. Use the Document.getDefaultRootElement() method to get the first root Element. From there you can iterate through all the Elements. You should then be able to check the attributes of the element to see if it contains the Bold attribute using something like:
    AttributeSet attributes = element.getAttributes();
    if ( attributes.containsAttribute(StyleConstants.Bold, Boolean.TRUE)
    // do processing here

  • How to get Document Set property values in a SharePoint library in to a CSV file using Powershell

    Hi,
    How to get Document Set property values in a SharePoint library into a CSV file using Powershell?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi,
    According to your description, my understanding is that you want to you want to get document set property value in a SharePoint library and then export into a CSV file using PowerShell.
    I suggest you can get the document sets properties like the PowerShell Command below:
    [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
    $siteurl="http://sp2013sps/sites/test"
    $listname="Documents"
    $mysite=new-object microsoft.sharepoint.spsite($siteurl)
    $myweb=$mysite.openweb()
    $list=$myweb.lists[$listname]
    foreach($item in $list.items)
    if($item.contenttype.name -eq "Document Set")
    if($item.folder.itemcount -eq 0)
    write-host $item.title
    Then you can use Export-Csv PowerShell Command to export to a CSV file.
    More information:
    Powershell for document sets
    How to export data to CSV in PowerShell?
    Using the Export-Csv Cmdlet
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Sharepoint Workflow : how to get document full path + file name into variable?

    Hi,
    Anybody knows how to get document full path + file name into a variable in Sharepoint 2010 workflow?
    Example http://sp1:80/InvoiceQueue/Shared Documents/123.pdf
    I am using List Workflow which links to a document library.

    Hi SAMSUNG,
    According to your description, my understanding is that you want to get the full path of a document in a list workflow.
    You can set the variable to the Enconded Absolute URL of the document. The screenshot is my testing. In my testing (in the red area), when the title of a document was equal to the tile of the current item, set a variable to the Enconded Absolute URL of the
    document. I used ‘Log to history list’ to check the value of the variable in Workflow History .
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • How to get documents in BPS

    Hi
    Someone can help me with how to get documents in BPS, Is there one how to.... documents in BPS?
    We try to use the function modules UPC_DOCUMENT_GET and UPC_DOCUMENT_LIST_GET but is not working because is missing parameters.
    Thanks
    Vero

    Veronica,
      I am assuming that you want to know how documents are
      handled in BPS and how you can configure your system to
      do so.
      Here is the "How to" paper that explains this:
      https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/biw/g-i/how%20to%20handle%20documents%20in%20sem-bps%20and%20bw-bps.doc

  • How to get documents from RMS linked to particular case id using webdynpro

    HI friends,
    Can  anybody knows " How to get documents from RMS linked to particular case id."
    From end: webdynpro
    backend: RMS.
    please do the needful.
    Thanks and Regards
    -Sujatha

    HI friends,
    Can  anybody knows " How to get documents from RMS linked to particular case id."
    From end: webdynpro
    backend: RMS.
    please do the needful.
    Thanks and Regards
    -Sujatha

  • How to get document liked to material

    How to get documents liked to certain material? I have material number and I want to get the document number of each linked document.
    I tried to use MATERIAL_READ_DOCUMENTS function, but the call returned "SYSTEM_FAILURE".
    Here is the code:
    theFunc = functionCtrl.Add("MATERIAL_READ_DOCUMENTS")
    theFunc.exports("MATNR") = matNum
    materialDocuments = theFunc.tables("IDRAD")
    returnFunc = theFunc.Call
    If returnFunc = True Then
        rows = materialDocuments.rowcount
        ReDim dataTable(rows, 1)
        For i = 1 To rows
            dataTable(i, 0) = materialDocuments(i, "DOKNR")
            dataTable(i, 1) = materialDocuments(i, "DOKAR")
        Next i
    Else
        callException = theFunc.Exception
    End If

    Hi,
    One soloution would be to use the BAPI,
    BAPI_DOCUMENT_GETOBJECTDOCS.
    Pass 'MARA' to field OBJECTTYPE and the 18 digit material number to field OBJECTKEY and u will get all the material document links assosiated with the material. What more, it is a BAPI so it is RFC enabled.
    Hope this helps.
    Sharath.

  • How can get document from mac to iphone

    How can I get document from imac that is saved, to my iphone?

    What kind of document?
    iWork documents (Pages, Numbers, Keynote) can be saved to iCloud and opened by the corresponding apps on the iPhone.
    PDFs can be transferred via iTunes or Dropbox and read using an application such as Goodreader.
    If you can add some detail to your request, we can try to offer a better solution.
    Matt

  • How to get document for jdbc-subprotocol

    I want to know,which subprotocol supports the jdbc.How to get the document of this.

    That question is either way to open ended, or you are using the terms in a way that is not normally meant.
    Maybe something here would help you .... http://java.sun.com/products/jdbc/

  • How to get documents into adobe reader iphone

    hi all -- new to my iphone -- i want to read pdfs using the adobe reader -- how do i get pdfs loaded into ???? so the phone can download it

    hazardzzz,
    Please take a look at the following FAQ document to see if it helps you get started with Adobe Reader on your iPhone.
    How to get PDF documents into Adobe Reader for iOS (iPhone on iOS 7 version)

  • How to get Documents folder back in the Dock?

    Hi all
    While playing Leopard, I accidentally removed the Documents folder from the dock. Anyone know how to get it back in its original form (ie- not adding the Alias, but the stackable, entire Documents folder)?
    many thanks

    Thanks.
    I am an idiot.
    I tried to drag the Documents folder from the sidebar and it wasn't working. Now I did it from my home folder and its fine.

  • How to get the correct length...removing appended extra ascii characters

    I have a table fs_lg_partgroups, having the columns description,subgroupname.
    I have a query like this..
    select description,length(description) from fs_lg_partgroups where subgroupname='FORMULA226';
    Then i got the output as
    formula226 and the length is 42. Even though there are 10 characters only.
    I came to know that some ascii characters are appended to description values, so it is showing the length like this.
    But i don't know how to remove those ASCII characters from description column for all rows to get the exact length.
    Please can u help me..

    If you have used char data type then use varchar2 datatype instead of char datatype for description column.
    Learn about char and varchar2 datatypes here.
    http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96524/c13datyp.htm#7223

  • How to get the time length from send record command to record video really?

    I have two buttons. Record/Stop
    I press Record button to record the video and press Stop
    button to stop recording.Now,I spend 1986 ms from press Record
    button to press Stop button.
    But the flv file's length is 1920 or 1910 or 1915 ms.
    So I want to get the time length from send record command to
    record video really.
    Can you give me some suggests.
    Thanks!

    maybe you have lag in publishing.... are you try watch de
    NetStream.liveDelay() method?
    or start counting when NetStream.onStatus has
    "NetStream.Record.Start" and "NetStream.Record.Stop" in information
    objects....

  • How to get document object on kBeforeOpenDocSignalResponderService

    Hi ,
    I want to change the document on kBeforeOpenDocSignalResponderService.
    I have tried following code on kBeforeCloseDocSignalResponderService
    case kBeforeCloseDocSignalResponderService:
    InterfacePtr<IDocumentSignalData> documentSignalData(signalMgr, UseDefaultIID());
    if (!documentSignalData)
          CAlert::ErrorAlert("documentSignalData is Nil");
         break;
    UIDRef documentUIDRef = documentSignalData->GetDocument();
    if (documentUIDRef.GetDataBase() == nil)
          break;
    InterfacePtr<IDocument> document(documentUIDRef, UseDefaultIID());
    if(document == nil)
         break;
    but here i am not able to get document object.
    Is there any way to achieve it.
    Please suggest some way
    Thanks,

    Hi Pooja_IDDev,
    void MyImpl::Respond(ISignalMgr* signalMgr)
         do{
              ServiceID serviceTrigger = signalMgr->GetServiceID();
              InterfacePtr<IDocumentSignalData> docData(signalMgr, IDocumentSignalData::kDefaultIID); //kDocumentSignalMgrBoss
              if(docData == nil)
                   break;
              UIDRef doc = docData->GetDocument();
         }while(kFalse);
    Best regards,
    Oleg

  • How to get document's Bleed Box

    Hi all,
    I want to get the current bleed settings of a document, but can't find any class in the SDK making this available.
    There is INewDocCmdData which allows to set the bleed box for a new document, so if there is a way to get an INewDocCmdData for an existing document, that would work. But I don't know how to achieve that either.
    Another option seems to be via the script interface. There are Javascript classes and methods defined to get a document's bleed box. But can I somehow run a short script snippet from within C++ and extract the result?
    Any pointers would be really great.
    Bernd

    Look to IPageSetupPrefs on the document boss.
    Ian

Maybe you are looking for

  • Home Sharing: Can't see anyone's iTunes

    My iTunes is detectable on other computers but mine won't detect anyone's. We are on same network. I have closed and opened iTunes, I have tried different homesharing accounts. Fixed firewall stuff and network stuff. My brother and I both have HP com

  • Newbie to Hibernate

    Hello, I am starting to use Hibernate and am working on some examples in order to see it working. I am now working on this one-to-many example that is raising exceptions that I am not beeing able to get rid of nor have I found anything clear enough,

  • Bug in WL5.1 Console

    Server: WLS 5.1 SP9 Solaris Console: WL5.1 SP9 swing console from Linux, connecting to WLS 5.1 SP9 on Solaris Using the console, under "Deployed Beans", clicking on the beans that you have deployed shows you how many transactions have been committed,

  • How to create JCo to call R3 transaction

    Hi Expert, I am new to CRM Webshop. Can someone tell me whether it is possible to call R/3 transaction from JCo? I need to call transaction /AFS/ATPS and display the screen to the user. Thanks

  • Can anyone recommend this?

    First off, I would like to thank Kappy for answering my last question. It really helped. Now, I was wondering if anyone could recommend an app where I could write essays, book reports, research papers, etc. sort of like microsoft word so I could do w