How to gain access to a label added to JTextPane

I have a JTextPane that uses text and JLabels. I need to be able to gain access to both the text and the JLabels' text. I 've looked at both the structure and the veiw structure but haven't been able to solve this. Could someone give me a strategy.
Thanks

Camickr,
The following code represents the three methods that I have used to get the text imbedded within the label inserted in line in a JTextPane. If you run the code the first data that comes out is the Document dump. This shows that in the example there are three paragraphs. In each of the paragraphs is content and components. What I am trying to accomplish is to get the text from the JLabel. Or the name field from the dump. I have no clue how to get these.
The second approach was to go down the elelment structure and attempt to get the name. It appears that the name I am printing is the attribute name(default). This is not what I want. I am looking for the name that appears in the dump, what ever that is.
The third approach is to use the view structure. The view structure is not providing what I expect. I would have expected a separate view for the components and the other content. I should site that the view structure code borrows heavily from Kim Topley's Swing Advanced Programming.
I would really appreciate any help you can provide.
Regards,
Sandy
package javaapplication6;
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
* @author Sandy
class TestJTextPane extends JFrame
    private Style style;
    private JTextPane DisplayLetterPane;
    private DefaultStyledDocument sDocument;
    private StyleContext sContext;
    private JLabel label;
    public TestJTextPane()
        loadTextPane();
    public void loadTextPane()
        sContext = new StyleContext();
      sDocument = new DefaultStyledDocument(sContext);
      Style defaultStyle = sContext.getStyle(StyleContext.DEFAULT_STYLE);
      DisplayLetterPane = new JTextPane(sDocument);
      try
              sDocument.insertString(sDocument.getLength(), "The first president of the US was ", defaultStyle);
              createLabel("George Washington");
              sDocument.insertString(sDocument.getLength(), " ", style);
              sDocument.insertString(sDocument.getLength(), ". He was the father of our country.\nThe second president of the US was", defaultStyle);
              createLabel("John Adams");
              sDocument.insertString(sDocument.getLength(), " ", style);
              sDocument.insertString(sDocument.getLength(), ". He came from Mass.\nThe third president of the US was", defaultStyle);
              createLabel("Thomas Jefferson");
              sDocument.insertString(sDocument.getLength(), " ", style);
          catch(BadLocationException Ble)
                System.out.println("Ble");
      System.out.println("********************* AbstactDocument Dump ****************");
      ((AbstractDocument)DisplayLetterPane.getDocument()).dump(System.out);
      System.out.println("********************** Document Structure *****************");
       Element section = DisplayLetterPane.getDocument().getDefaultRootElement();
         for(int p = 0; p < section.getElementCount(); p++)
             Element para = section.getElement(p);
             for(int q = 0; q<para.getElementCount(); q++ )
                 System.out.println(para.getElement(q).getName());
                 if(para.getElement(q).getName().equals("content"))
                     try
                        System.out.println( DisplayLetterPane.getDocument().getText(para.getElement(q).getStartOffset(), para.getElement(q).getEndOffset()- para.getElement(q).getStartOffset()));
                     catch(BadLocationException ddd)
                 else
                       System.out.println( "73 " + para.getElement(q).getStartOffset() + " " + para.getElement(q).getEndOffset());
                      Style holdStyle = sDocument.getLogicalStyle(para.getElement(q).getStartOffset());
                      System.out.println(holdStyle.getName());
       System.out.println("******************** View Structure ***************");
       View rootView = DisplayLetterPane.getUI().getRootView(DisplayLetterPane);
      System.out.println( "82 " + rootView.getViewCount()+ " " + DisplayLetterPane.getDocument().getLength());
      displayView(rootView,  DisplayLetterPane.getDocument());
    public static void displayView(View view,
                         Document doc) {
          String name = view.getClass().getName();
                System.out.println("88 " + name + "viewcount " + view.getViewCount());
//          for (int i = 0; i < indent; i++) {
//               out.print("\t");
          int start = view.getStartOffset();
          int end = view.getEndOffset();
          System.out.println(name + "; offsets [" + start + ", " + end + "]");
          int viewCount = view.getViewCount();
          if (viewCount == 0) {
               int length = end - start;
               try {
                    String txt = doc.getText(start, length);
//                                String txt1 = doc.getText(90, 98);
//                                System.out.println("xxx" + txt1);
                    System.out.println(name + "; offsets [" + start + ", " + end + "]" );
                    System.out.println("104 [" + txt + "]");
               } catch (BadLocationException e) {
                            System.out.println("amihere");
          } else {
               for (int i = 0; i < viewCount; i++) {
                            System.out.println("110 " + viewCount);
                    displayView(view.getView(i), doc);
    public void createLabel(String presName)
       label = new JLabel(presName);
       FontMetrics fm =  label.getFontMetrics( label.getFont());
       label.setPreferredSize(new Dimension (fm.stringWidth(presName), 26));
       label.setMaximumSize(new Dimension (fm.stringWidth(presName), 26));
       label.setMinimumSize(new Dimension (fm.stringWidth(presName), 26));
       label.setVerticalAlignment(JLabel.TOP);
       label.setOpaque(true);
       label.setBackground(Color.CYAN);
       style = sDocument.addStyle(label.getText(), null);
       StyleConstants.setComponent(style, label);
public class Main {
     * @param args the command line arguments
    public static void main(String[] args) {
        // TODO code application logic here
        TestJTextPane TJP = new TestJTextPane();
}

Similar Messages

  • How to gain access to "what's new in Leopard" etc since HELP in OS is dead

    Since the links in my Apple HELP seem to be dead in spite of trying all of the suggestions here on the board (and apparently I'm not alone - others are having problems with Apple HELP as well), does anybody have an alternative way I can gain access to these links?
    I just got my Mac and was hoping to sit down and take a little tour, et al to become acquainted with new features, etc. of this newest of Apple's OS. Suggestions?

    I have no idea what is wrong. If, instead of typing something in the Search box, you simply click the Mac Help link below the search box does the Help viewer launch? If not, what message do you see in the Console?
    Since the stuff is all written in perfectly normal html, it used to be relatively easy to browse the help files with Safari. That is no longer the case, since they has seen fit to make all the links some weirdo thing that automatically opens the Help Viewer. However, all the pages are actually here:
    "/Library/Documentation/Help/MacHelp.help"
    Control click and select "Show Package Contents" then open the Contents folder, the Resources folder and English.lproj folder. All the html pages are in there, and each one will open when double clicked in Safari. However because the links specify something strange, clicking on one opens the page in Help Viewer rather than Safari. It is possible to figure out what is where, but it isn't easy and it isn't convenient. You would be better off to just browse Apple's web site, starting here:
    http://www.apple.com/macosx/features/
    Personally, I find the new Help more annoying that helpful anyway--the Help window is programmed to always stay on top, thus making it impossible to work back and forth between it and whatever you are doing, unless you have two monitors and can move it to the second monitor.
    Francine
    Francine
    Schwieder

  • How to gain access to second Linux partition

    Hi,
    Before I start, I'd just like to say how impressed I am with Arch! I've only been using it for a week now, a bit less in fact, but it's already wowing me enough to make me think about changing my loyalties from Debian to Arch - something I thought would be impossible even a few weeks back!
    Anyway, my problem is, should be a simple one this, how to access my Arch partition from Debian and vice versa. In Debian, I can see the Arch partition in Dolphin, but when I click on it I get a permission denied message. When I try to mount this device (in Dolphin not with the command line) I get the same message. Now, in the bad old days when I shared my Linux computer with Windows, I was able to access my FAT32 partition by simply going into /media, finding the partition (let's say hda2) and chmod-ing it, ie chmod 0777 /media/hda2. I wanted to see if this would work with my Arch partition, but I don't even see it in /media/ Instead I went into /dev and tried changing permission there, but to no avail. I've tried tinkering around with the fstab file, but I'm very much an amateur at this, and now I don't know what to try. Here is the result of fdisk -l (hda1 is Debian):
    Disk /dev/hda: 80.0 GB, 80026361856 bytes
    255 heads, 63 sectors/track, 9729 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Device Boot Start End Blocks Id System
    /dev/hda1 * 1 7047 56604996 83 Linux
    /dev/hda2 9447 9729 2273197+ 5 Extended
    /dev/hda3 7048 9446 19269967+ 83 Linux
    /dev/hda5 9447 9729 2273166 82 Linux swap / Solaris
    And here is the fstab file (I have myself entered the line for hda3):
    debian:/home/james# cat /etc/fstab
    # /etc/fstab: static file system information.
    # <file system> <mount point> <type> <options> <dump> <pass>
    proc /proc proc defaults 0 0
    /dev/hda1 / ext3 defaults,errors=remount-ro 0 1
    /dev/hda3 / ext3 defaults, errors=remount-ro 0 0 2
    /dev/hda5 none swap sw 0 0
    /dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0
    /dev/hdd /media/cdrom1 udf,iso9660 user,noauto 0 0
    /dev/fd0 /media/floppy0 auto rw,user,noauto 0 0
    /dev/sdb1 /media/usb0 vfat rw,user,users,noauto,noatime,noauto 1 2
    Can anyone help me with this?
    Thanks a lot in advance.

    Thanks for your reply toliman. I've tried doing what you suggested but it still doesn't work. Here is my new fstab file:
    # /etc/fstab: static file system information.
    # <file system> <mount point> <type> <options> <dump> <pass>
    proc /proc proc defaults 0 0
    /dev/hda1 / ext3 defaults,errors=remount-ro 0 1
    /dev/hda3 /media/arch ext3 defaults, errors=remount-ro 0 0 2
    /dev/hda5 none swap sw 0 0
    /dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0
    /dev/hdd /media/cdrom1 udf,iso9660 user,noauto 0 0
    /dev/fd0 /media/floppy0 auto rw,user,noauto 0 0
    /dev/sdb1 /media/usb0 vfat rw,user,users,noauto,noatime,noauto 1 2
    And here is the result of ls -l /media:
    drwxr-xr-x 2 root root 4096 2008-05-14 16:43 arch
    lrwxrwxrwx 1 root root 6 2007-06-07 17:13 cdrom -> cdrom0
    drwxr-xr-x 2 root root 4096 2007-06-07 17:13 cdrom0
    drwxr-xr-x 2 root root 4096 2007-06-07 17:13 cdrom1
    lrwxrwxrwx 1 root root 7 2007-06-07 17:13 floppy -> floppy0
    drwxr-xr-x 2 root root 4096 2007-06-07 17:13 floppy0
    drwxr-xr-x 2 root root 4096 2008-04-03 14:17 IOMEGA_HDD
    drwxr-xr-x 2 root root 4096 2008-01-10 14:56 sda1
    drwxrwxrwx 2 root cdrom 4096 2007-12-15 20:44 usb0
    Still the same issues: pemissions denied when I try to open or mount hda/3 with dolphin. When I try to mount as root using the command line I get:
    debian:/home/james# mount /dev/hda3
    [mntent]: line 6 in /etc/fstab is bad
    mount: can't find /dev/hda3 in /etc/fstab or /etc/mtab
    Thanks once again.

  • How could we access UDF's label in FMS?

    Hi all,
    I have many user defined fields at Item Master Data level.
    I would like to access the text of the labels of the User Defined Fields we have created. Is this possible for a FMS and regular SAP B1 query?
    Please provide an example to do so please. Thank you.

    You can run query like this:
    SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'OITM' and COLUMN_NAME like 'U_Depositfee%'
    FMS can only get the first column value.
    Thanks,
    Gordon

  • I cannot locate my original SN from Aperature 2.  I have the Aperature 3 upgrade SN but that is not acceptable. How doI gain access?

    I cannot locate my original SN fron Aperature 2.  I have the Aperature 3 upgrade SN but that apparently is not acceptable.  Help!

    Contact Apple and ask for a "Replacement Serial Number".
    You will need to provide a proof of purchase:
    See this page: Pro Application Replacement Serial Numbers

  • Time Capsule - how to gain "over-the-internet" access from Windows 7!

    Hi guys,
    I've been fighting for such a long time with my Time Capsule. I have no idea how to gain access "over-the-internet" on a PC (Windows 7) which is running on  another network. My Time Capsule is set up with my Macbook Pro at home running Lion OSX, and i have internet connection. My brother who also uses Macbook has no problems connecting to my Time Capsule - through finder (connect to a server). But how do I gain "over-the-internet" access to my Time Capsule through a PC (Windows 7) from my office? Is there please someone who can guide me step-by-step, how to gain connection to my TC through a PC? Or maybe just an explantaion what has to be done on the PC before this thing can work out! This was the main reason to why i bought Time Capsule - besides of the Time Machine function. I also have an iCloud account (earlier Mobile Me), if that makes any difference.
    Thanks!

    There is no way to do it from windows direct to the TC.
    It only presents AFP to the WAN side. And most ISP block SMB from internet access due to risks. There is AFAIK, no suitable AFP protocol utility for windows at the moment. If you google and find one, be aware it probably will not work to your satisfaction anyway.
    You must use a Mac to access AFP but even then it is not a secure protocol and I would recommend against it anyway.
    So basically if you had have asked before purchasing, I would have said, TC is unsuitable product. It is a backup drive for a Mac. It is not a NAS.. it is not designed for remote access by any computer other than a Mac. It does not support any other file protocol to the WAN interface.. and no secure protocol even there.
    A NAS with Time Machine extensions from QNAP, Synology, Netgear all are designed for web access and are far more suitable. Researching a purchase beforehand is always worthwhile.
    Anyway, your choices are.. return the TC and buy something more suited to the job.
    Or if return is now impossible sell the TC on ebay.. etc and do the same thing.. buy a more suitable NAS.
    Or buy a cheap mac mini (even second hand) and use that for communications with home.
    Or, replace your current router with something that includes vpn. This is actually a good and commercially sound decision. VPN is generally used by business to connect to remote locations, because it is secure and will allow the greatest flexibility of connection. How hard or easy depends on the current setup. I would recommend a combined modem router with vpn server if you have adsl. Or for cable you can find plenty of routers with combined vpn. You can also use those for adsl if your ISP allows pppoe with bridged modem. The TC will have to be bridged as well. For other broadband it might be harder to find the right kind of box.
    Once you setup a vpn you can access it from work using the appropiate vpn client in your work computer.

  • How can I access audio over Firewire from a DV camera in Flex/Air?

    Hi all,
    I've scoured the 'net looking, but I cannot seem to find an answer to my question.
    I'm writing an app that captures video and audio in Flex as an Air application.  I can use Camera.getCamera() to get the video from my Firewire-connected DV camera just fine, but the audio stream doesn't show up in Microphones at all.
    I'm developing on Windows 7 - is there some issue with Windows not exposing the Firewire audio feed as a local sound device?  Is there a way around it?
    Thanks in advance - I look forward to any help you may be able to offer.
    Dave

    I should note that the camera (both video and audio) show up as devices just fine in other Adobe CS apps (including FLME).  Does anyone have any insight as to how FLME gains access to the DV hardware?

  • I lived in the US for a few years, spent a fortune on iTunes [my then local Apple ID account].  Now I live in South Africa and want to use Match.  I have a local credit card but how do I use my new / 2nd Apple ID and gain access to all my US music??

    I lived in the US for a few years, spent a fortune on iTunes [my then local Apple ID account].  Now I live in South Africa and want to use Match.  I have a local credit card but how do I use my new / 2nd Apple ID and gain access to all my US music??

    You have to be in a country to use its store - you will need to be in the US and have a US billing address on your account to be able to use the US store (that applies to buying and redownloading).
    You can use iTunes Match in South Africa, do you not have a backup copy of all of your US iTunes purchases so that you can subscribe to it and upload those that aren't in the South African store to it ?

  • How can my replacement gain access to all the files on my work computer

    I am retiring from my place of employment after 14 years on the job--my choice as I've reached retirement age.  I've been a Mac guy for over 5 years now and my replacment is inheriting my computer, a Mac Pro with a 2TB hard drive I added a couple of years ago when I outgrew the original 750GB drive (which is still installed).  I use Mail which has probably 100,000 stored messages, and all of my documents...tons of them.  My replacement needs to take over the machine and "make it hers" but she will still need to have access to all my "stuff" to continue in the position...all my mail, calendar, address book, and documents for MS Office 2011, Adobe CS programs, etc.
    I went to the users part of system preferences today and added her as a new identity and as an administrator, but it gives here a "virgin" finder, without all the additions I had put in the sidebar of my finder, etc.  In fact it defaulted to the original "Macintosh HD" which I had nearly filled until I added the second hard drive, the one that is 2TB in size.
    Is there a way to configure the Mac Pro (it uses Lion and is too old to upgrade to Mountail Lion) so that she can gain access to all of my "stuff"?
    Rock

    See Pondini's Transferring files from one User Account to another.

  • I want to set up my Apple Airport Express router to gain access to Unblockus. How do I do that?

    Does anyone know how to set up the Airport Express router to gain access to Unblockus.
    Unblockus has provided me the Preferred and Alternate DNS server numbers. I just dont
    know how to configure the Airport Express router to accomodate this DNS address.
    Also I dont want to negate the DNS address I already use to gain access to my internet service
    provider, when I do this.
    Help....

    I just dont
    know how to configure the Airport Express router to accomodate this DNS address
    Caution......This will overwrite any existing values that you have in the DNS Server boxes. There is no way to keep your existing DNS numbers if you enter new DNS numbers.
    Open Macintosh HD > Applications > Utilities > AirPort Utility
    Click on the AirPort Express
    Click Manual Setup
    Click the Internet icon at the top of the AirPort Utility window
    Click the TCP/IP tab
    Enter the Primary and Secondary DNS numbers in the DNS Server boxes
    Click Update to save the new settings

  • I recently updated my e-mail address with apple, but now it does not show all the "purchased" music that I purchased under my old e-mail address.  How can I re-gain access to those hundreds of purchased songs?

    I recently updated my e-mail address with apple, but now it does not show all the "purchased" music that I purchased under my old e-mail address.  How can I re-gain access to those hundreds of purchased songs?

    You are trying to find a loophole to circumvent a basic rule that prohibits the transfer of purchased content from one Apple ID to another.
    Content tied to an Apple ID are bound to that Apple ID forever. You can not merge or trade accounts. Well, not (officially) anyway...

  • How do I sync hotmail passwords so i can gain access to my hotmail inbox wihtout having to retype my password all over again

    How do I sync hotmail passwords so i can gain access to my hotmail inbox wihtout having to retype my password all over again

    Hi there,
    When you enter your username/password combination for the first time Firefox will ask you to remember it. Clicking yes will result in FF filling it in for you on your next visit. Please keep in mind that cookies must be enabled in order for this to work.
    Regards,
    Ziggy

  • How can I access keywords in adobe bridge after labeling them?

    How can I access keywords in adobe bridge after labeling them?

    There's a search box in the upper right corner of Bridge. Just type in the keyword and it should show up in the Content Panel.
    What if you want to save your search in a Smart Collection?  A folder that would permanently hold the results of your search?
    You'll love this video.
    http://www.lynda.com/Photoshop-tutorials/Using-smart-collections/97619/103735-4.html
    Gene

  • HT1920 I no longer have access to the recue email and cannot remember my password how do I process to gain access to my iTunes account?

    I no longer have access to my recue email address and cannot remember my password how can I gain access to my itunes account? I have opened a new itunes ID but would like to transfer over all my music from my old account
    Best regards
    Philip

    You can't transfer any content from one account to another account, all content will remain tied to the account that downloaded it.
    If this page doesn't let you get access to your old account : http://iforgot.apple.com, then you will need to contact iTunes Support / Apple to get access to it : http://support.apple.com/kb/HT5699 (if you've also forgotten the answers to your security questions then they should also be able to reset them)
    When you've got access to your account you can then use the steps half-way down this page to update your rescue email address for potential future use : http://support.apple.com/kb/HT5312

  • Itunes now requesting PW for old purchases. Current PW does not work. How to fix and gain access to songs purchased 6 years ago. Other, more recent songs all OK.

    Itunes now requesting PW for old purchases. Current PW does not work. How to fix and gain access to songs purchased 6 years ago. Other, more recent songs all OK.

    If you bought the music with another itunes account, then you will have to authorize the computer for that account.

Maybe you are looking for