The Artima Developer Community
Sponsored Link

Java Answers Forum
Getting Text from JTExtPane

1 reply on 1 page. Most recent reply: Oct 1, 2002 10:14 PM by Singh M.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
thilko richter

Posts: 1
Nickname: smilie79
Registered: Sep, 2002

Getting Text from JTExtPane Posted: Sep 30, 2002 9:34 AM
Reply to this message Reply
Advertisement
Hi!

I have a problem: I have to write some kind of editor but with own defined tags. So when the text is marked with some styles (bold, etc) I must wrap the part with the special style with a own defined tag. i.e.
<myOwnTagStyleName>.....</myOwnTagStyleName>
I found nothing about this theme. It is possible to ask every character abaout his Element? But what should I do when I get a picture - or should I say - what happens?

Thanks a lot,

Smilie79


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Getting Text from JTExtPane Posted: Oct 1, 2002 10:14 PM
Reply to this message Reply
It is possible to ask every character abaout his Element?

Yes it is possible to do that. Let us take an example of an editor for working with java files. If the syntax highlighting is functional, and you want to check whether a given offset is a part of a method name, then you can do it as follows....



    private boolean isMethodNamePart(int offs) throws BadLocationException{
        Element element = this.getCharacterElement(offs);
        AttributeSet attributes = element.getAttributes();
        
        if (attributes.containsAttributes(attributeToCheck)){
            return true;
        }
        
        return false;
    }


This demonstrates that you can ask every character about its properties. This eg. assumes that your class extends DefaultStyledDocument. Just do some search, you will find something for JTextPane too.

Flat View: This topic has 1 reply on 1 page
Topic: encryption/security problems Previous Topic   Next Topic Topic: Using Stringtokenizer to add to DoubleLinkedList

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use