How to associate Document and JTextPane  ?

Hello,
I'm a little lost and confused about JTextPane.
I thought that to associate a document and a JTextPane, the method JTextPane.setDocument(doc) had to be used.
But by looking at the sample : http://bioportal.weizmann.ac.il/course/prog2/tutorial/uiswing/components/example-1dot4/TextSamplerDemo.java, I haven't seen any such instruction. The code is the following :
        JTextPane textPane = new JTextPane();
        StyledDocument doc = textPane.getStyledDocument();
        addStylesToDocument(doc);
        try {
            for (int i=0; i < initString.length; i++) {
                doc.insertString(doc.getLength(), initString,
doc.getStyle(initStyles[i]));
} catch (BadLocationException ble) {
System.err.println("Couldn't insert initial text into text pane.");
I understand that the document "doc" is associated with  "textPane" , but I do not understand, how Java knows that in this JTextPane, the document to be displayed must be  "doc" ?  However it works (miracle ???).   
I'm wondering whether it is  not because the Document Listener retrieves the JTextPane information from the Document, and then triggers the  JtextPane update from the document.  But I'm not sure.
Thanks to gurus to let me understand.   
Gege                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Thanks a lot Camickr for your answer. But does this mean that when I type :
StyleDdocument doc = textPane.getStyledDocumen();
I do not really create a document, but I only get the reference of the empty document ? If it is right, then I understand why the following code does not work.
Among my various tries, I sightly modified the TextSamplerDemo sample to add a second JTextPane (that I did not add to the JPanel).
JTextPane textPane = new JTextPane();
JTextPane textPane2 = new JTextPane();
StyledDocument doc = textPane.getStyledDocument();
doc = textPane2.getStyledDocument();
addStylesToDocument(doc);In such a case, textPane becomes empty, but when I add te instruction : textPane.setDocument(doc); it starts working again.
Thanks again for your help, I hope you have understood my English (which is not my natural language).
gege

Similar Messages

  • How to delete documents and data off of iphone 4s

    Im trying to free up some room on my phone. I got rid of some apps and movies and did what i can but when i plug my phone in there is more Documents & data then i have as apps and music. i just want to get ride of some documents that are saved in my phone but  dont now hot to delete them.

    Document & Data on iPhone is junks files including browser history, cookies, logs, caches of photos and videos, database files stored by your apps. You’ll notice that some apps while being very small themselves have accumulated a lot of data. An example of this is shown in the image below, you see that the Facebook app is 109 MB whereas the Documents & Data stored is 1.2 GB. This 1.2 GB is what goes into your “Other” data.
    These apps on iPhone don’t provide a way to delete Documents and Data, uninstalling and reinstalling the app is not the best option here. With the help of CleanMyPhone or PhoneClean you can delete the documents and data on iPhone without deleting the app itself.
    Resource: http://www.fireebok.com/resource/how-to-delete-documents-and-data-on-iphone.html

  • How to save documents and photos on my passport

    how to save documents and photos on my passport

    What passport are you referring to? What os are you running on your MacBook Pro? iOS is for iPhone, iPad not for Mac computers.

  • How to clear documents and data for third party applications

    Anyone can help me how to clear the documents and data for apps like facebook , i tried to delete the app and re-install but there is no change , please advise ,
    thank you.

    Manage the data on the device via iTunes.

  • How to connect documents and icloud ?

    How do i connect documents and icloud?

    You can store iWorks docs on iCloud, but you cannot share them with others.  The old iWorks beta web site let you host files for other remote users to have access to them, and iCloud (at least not now) does not allow that.

  • How to move Documents and Settings and All Libraries To D drive to separate from the OS

    I want to move my Documents and settings Folder to D drive so I can back up the OS separate from Data or at least move Libraries to D drive. I have partitioned my hard drive so that most of the space is on D drive and about 100G is on C drive. I can't understand why the old My Documents file structure was changed where now it is called Libraries and My Documents is a sub folder to that and My Music, My Picture etc are not in My Documents anymore. Let’s just randomly shuffle directories to enhance the Window 7 experience. If you have not already figured out I am an XP user. I know there is a way to do what I want to do because virtually all corporate systems are setup this way.
    Oh how the heck to I get access to Documents and Settings? Well sometimes programs hide stuff there. Like why does Zune software hide your album art in documents and settings that you spent hours downloading and fixing so that when you move my music that all your album art does not go with it.
    Perry

    Hi,
    In Windows Vista and Windows 7, the “My Documents and Settings“, has been replaced by "Users". The My Documents, My Music, My Pictures, and
    My Videos folders in Windows XP are transferred to the following folders in Windows 7:
    %systemdrive%\Users\user_name\Documents
    %systemdrive%\Users\user_name\Music
    %systemdrive%\Users\user_name\Pictures
    %systemdrive%\Users\user_name\Videos
    You can find your user files in the above folders and move them to the drive you like.
    For more information, please refer to
    http://support.microsoft.com/kb/930128
    http://support.microsoft.com/kb/930890
    It applies to Windows 7.
    Hope it helps.
    Vivian Xing - MSFT
    When I visit the two quoted knowledge base links from Windows 7 I get -
    System TipThis article applies to a different version of Windows than the one you are using. Content in this article may not be relevant to you.Visit the Windows 7 Solution
    Center
    In other words your reply does not apply to Windows 7.
    Do you please have an answer which does apply to Windows 7?
    Cheers,
    Brian Towers

  • How to clear documents and data storage

    I cannot seem to get 6.08 worth of Gb off of my documents and data someone help!

    Manage the data on the device via iTunes.

  • How to delete documents and data from your iphone

    iphone 5s has a lot of things listed in "documents and data" section- and in the "other" section of itunes when updating phone- is there a way to know what is on there so i can delete it?  itunes does not give more information...

    These are 2 different things and have to be address 2 different ways.
    The other, that shows up in iTunes on the bar is memory the device is not recovering, for what every reason.
      To reclaim that you need to wipe the iPhone and setup as new.
    The Documents and Data in the iCloud storage.
      Tap the Doc or data type
      then swipe right to left on the data and press delete

  • How to delete "Documents and Data" without deleting App?

    iPad does not have any way to clear the "Documents and Data" items. I need the experts to help me out. Thanks

    The "Documents and Data" use up the memory and my iPad only has 16G ....

  • How to remove documents and data in iPhone 5?

    Before it was "Others" that was taking up so many spaces.  After upgrading to iOS7, it is now "Documents & Data" that's taking up 8.86 GB of space.  How to fix with out downloading 3rd party app?

    Like this? Ñ ñ? Push and hold the N until the choices appear above the key.

  • How to add Document and Comment in BI Query

    Hi All,
    I need one help from you, I am trying to upload some douement and comment in my BI query, after executing Query If i right click and Document --> Upload --> Comment/Document, I am getting following msg
    1. Cannot get properties for assignment
    2. Cannot get folder for assignment
    3. Error while lunching new document dilog
    looking for your help
    Samit

    Hi,
    selection screen parameters and select options is possible. I think radio buttons is also possible.
    Please check in AT-SELECTION SCREEN even available in the info set from SQ02.
    Regards,
    Santhosh.

  • How to Associate Project and Expenditure Org to Legal Entities

    This question is related to the "Derive Legal Entity from Organization Setup" Implementation Option for Intercompany Billing.
    Does anyone know how Proj/Exp Orgs are associated to Legal Entities? I believe Legal Entities are defined in GL Accounting Setup Manager, not in HR. So how does the system link a Proj/Exp Org defined in HR to a Legal Entity in GL?
    The guide states: "This option provides cross charge for intercompany billing within an operating unit and across legal entities by deriving legal entities from project and expenditure organizations. If an organization is not associated with legal entity establishment, then the legal entity from the operating unit is used by default."
    Regards,
    Adrien

    Shaan- the Org Hierarchy is where I can't see the connection: Legal Entities in the org hierarchy are HR organizations, but Legal Entities used in Intercompany Billing setup (e.g. Provider/Receiver Controls page) are GL Legal Entities setup in Accounting Setup Manager. Do you know how does the system connect HR LEs to GL LEs?
    Regards,
    Adrien

  • How to delete documents and data?

    iBooks is taking up space on my phone yet I have no books dosnloaded.  Why? And how do I delete?

    One way to do this for all of your apps is to connected the iPod to iTunes and restore it to factory settings versus restoring from a previous backup.
    iTunes: Backing up, updating, and restoring iOS software
    Otherwise, you'll need check each app to determine if they have a way of deleting/removing it's app specific data.
    B-rock

  • How to associate methods and pown to a dinamyc hierarchy.

    Hi experts.
    I created a hierarchy of societies and in the table associated to each one , I introduce the consolidation method and a pown and I save.
    The problem is when I return to that screen and I'm able to see neither the methods or powns I introduced.
    What is happening?
    Thanks.
    Edited by: vicente clemente rodriguez on Oct 22, 2008 6:04 PM

    cast root as a movieclip.

  • Report to show the followup sales documents and items

    Sales had executed many sales quotations with customers over a period of time.
    Now the Sales Staff wanted to know how many sales documents and what/how many sales items are being purchased by the customer with respect to the quotation.
    Is there a report that list out the sales documents and items created w/respect to a particular quotation instead of looking at the document flow which is difficult to diagnose.
    Thanks

    hello, friend.
    you can try table VBFA, where you can see sales documents and their subsequent documents.
    for a general listing of quotations, use tcode VA25.
    regards.

Maybe you are looking for