JTextPane, Selecting Text and Applying Styles

Hello,
Anyone encounter this situation? I have a mini word processor application that I have written using the RTFEditor kit and a JTextPane. To change style, e.g bold, font size, font face, etc, one can select text and then click a button or select a menu item. That part works fine. The styles are primarily changed by using the Action classes provided in the javax.swing.text.* package.
The problem is, that if a user selected text of more than one style, all of the text is automatically converted to the style of the first part of the text selected, without the user even eanting to change ANY style just yet.
If anyone knows why this might be happening I would surely appreciate it.
Thanks,
acal

Solution to the style appling problem...
public void actionPerformed( ActionEvent e )
        if (flag) return;
        if(e.getSource() == boldButton)
            SimpleAttributeSet attrs = new SimpleAttributeSet();
            attrs.addAttribute(StyleConstants.Bold,boldButton.isSelected());
            applyStyleToSelection(attrs);
            editorPane.grabFocus();
            return;
public void applyStyleToSelection(AttributeSet attrs)
        int start = editorPane.getSelectionStart();
        int end = editorPane.getSelectionEnd();
        DefaultStyledDocument doc = (DefaultStyledDocument) editorPane.getDocument();
        doc.setCharacterAttributes(start, end - start, attrs, false);
        StyledEditorKit styled = (StyledEditorKit) editorPane.getEditorKit();
        MutableAttributeSet mas = styled.getInputAttributes();
        mas.addAttributes(attrs);
    }Filipi Silveira
[email protected]

Similar Messages

  • Selection text and text elements contents not displayed

    I have a language related problem
    I have 2 servers .
    In first server I logged in english language and the selection text and text elements are displayed in English.
    The requirement is I dont want to translate these texts it should be displayed in English only even if I log into SAP with other language.
    So if I log in german I see the texts in English in the first server.
    But this is not the case with second.
    If I log in with English I see the english texts but if I do in german I am not able to see this english text with proper contents .
    Can anybody let me know if there are any settings to be done ? As its working fine in first server but not in second .
    Edited by: Jalpa Shukla on Oct 22, 2008 11:19 AM

    Hello Jalpa Shukla,
    If you want to display the text in english language only better dont use Text-element
    instead of using text element you hard the text in the program then you will display the text in same in English.
    Try in this way, If not past the code i will give the solution

  • Need to Update SELECTION TEXT and text symbols for report J_1IEWT_CERT.

    Hello Experts,
    My requirement is need to "Update SELECTION TEXT and text symbols for report J_1IEWT_CERT".
    1. As I want to change text sysmbols for 006 to "Run in preview mode". Currently it showing "Type of output". Issue I am facing here is that whenever I deleting aur changing the same it throws an error : "Text symbol 006 is an original text and cannot b
    deleted or renamed".  How can I do the same.
    2. Secondly I have to add two selection text also i.e. ZFATHER and PREV . And delete two selection text i.e. P_PDF and
    P_SCRIPT. In this Tab there is only a Icon of deleting not an Addition button .So How can I add two more selection text.
    Above are Manual Activities which is written in note 1486147. We already taken an acess key and it shows in editable mode but
    not able to add/deletin/modify selection text and text symbols.
    Please provide the solution as it is critical requirement.
    Reagrds,
    Supriya Bhatt.

    Hi Vishal Saxena,
    Just go through the screens and do it .
    [<li> Link1|http://4.bp.blogspot.com/_O5f8iAlgdNQ/SjoVqL9rnvI/AAAAAAAAEs4/fPG7IG9yGK4/s1600-h/3-716953.JPG]
    [<li> Link2|http://1.bp.blogspot.com/_O5f8iAlgdNQ/SjoVp3d9uEI/AAAAAAAAEso/ZxfkeNAiOZQ/s1600-h/1-715669.JPG]
    [<li> Link3|http://2.bp.blogspot.com/_O5f8iAlgdNQ/SjoVqIbpNpI/AAAAAAAAEsw/2ntYgX-i1Dc/s1600-h/2-716353.JPG]
    Thanks
    Venkat.O

  • Mass translation of text Symbols,Selection texts and Structures

    Hi,
    As per our Project Requirement we need to  maintain Mass translations for Text Symbols, Selection Texts and structures.
    Can anyone please provide a Tool or a solution through which we can maintain these translations without doing it manually
    through SE63 transaction .
    I have all the Translations maintained in a (.xls) file.
    Is it possible to provide this (.xls) (This .xls has the Original text and the Translated text) as a input and get the translations done.
    I would also like to know in which table these translations are maintained.
    Please help me with this.
    Thanks in Advance.

    Hi,
    There is no standard tool as such.
    You can use below technique to develop your own tool.
        READ TEXTPOOL 'Program name' INTO i_source LANGUAGE 'Language'.
        DELETE TEXTPOOL 'Program name' LANGUAGE 'Language'.
        INSERT TEXTPOOL 'Program name'  FROM i_target LANGUAGE 'Language'.
    Thanks,
    Vinod.

  • Can't select text and scroll when using Word

    Recently I have been unable to select text and scroll down the page using two fingers, while in a word document.This is only happening in Word, so far no other programs. Does anyone have an idea of how to turn on or off this feature?

    I cant scroll below or above viewable section of text in any of my Macbooks, iMac, Mac Mini. Never have been able to, never could, except by pressing the arrow keys whilst selecting, to move up or down.
    Its stupid
    I dont have flash installed (never will do since my first virus of video ad sound running in background from Cnet was downloaded and kept returning until i deinstalled flash).
    I believe that this is a universal issue because none of my Macs can scroll out of screen when selecting text, which as a webmaster and developer, is a pain in the butt
    My issue is not in word documents, its in everything

  • Create/find tables and apply style

    Hello,
    I'm very new to scripting. I want to learn the basics like creating a table, creating anchored frames, textframes, etc.
    Now, I want to create/find tables in a document and I would like to apply styles. I saw a script to do this. When I paste the script in Extendscript CS4, than the program crash.
    The program crash in part 1. When I create another script with only part 2 (see //part 2) then there is no problem.
    What do i wrong? And can anyone tell me what part 1 of the script do?
    Thanks,
    // part 1
    // using your version; I'd prefer to return 0 if table not found
    function findTable(obj) {
             while (obj.constructor.name != "Table") {
            obj = obj.parent;
            if (obj.constructor.name == "Application") {
                throw "Can't find table"
        return obj
    // part 2
    var myTable = 0;
    if (app.documents.length > 0 && app.selection.length > 0)
        myTable = findTable(app.selection[0]);
    // check for at least enough rows for 1 top row, 1 body row, 1 bottom row
    if (myTable != 0 && myTable.rows.length >= 3) {
        // delete all rules; set insets to 0
        myTable.cells.everyItem().appliedCellStyle = "[None]";
        // format bottom row
        // (remember rows uses 0-based count)
        a = myTable.rows.length - 1;
        myTable.rows[a].cells.everyItem().appliedCellStyle = "4.cell_body_last";
        // format middle rows
        first = 1;
         last = myTable.rows.length - 2;
        for (a = first; a <= last; ++a)
            myTable.rows[a].cells.everyItem().appliedCellStyle = "3.cell_body";
        // format top row
        a = 0;
        myTable.rows[a].cells.everyItem().appliedCellStyle = "2.cell_header";

    Part 1 expects the text cursor to be anywhere inside a table -- either in the regular text, or with a cell, row, column, or the entire table selected.
    It walks "up" using its parent until it arrives at the table object itself.
    This will only work if the text cursor actually is anywhere inside a table. It does nothing when you are somewhere else, and it only works with the "current" table.

  • Get Text with Applied Style

    Hi all,
    I am using InDesign CS3 on OS 10.5. I'm trying to write something in Applescript that can look at a document and give me the text that has a certain applied style.
    For example, if a document contained the text "Hello, world" and had an applied paragraph style called "Greeting," then what I want is to use my script to tell that document something like this:
    tell application "Adobe Indesign CS3"
    set theDoc to document 1
    set theText to get every paragraph of theDoc whose applied paragraph style is "Greeting"
    end tell
    theText
    -->should return: "Hello, world"
    Obviously, I tried that script, but it doesn't work. I get the error "Adobe InDesign CS3 got an error: Cant get every paragraph of document "MyDocument.indd" whose applied paragraph style = "Greeting"."
    I'm not sure if I am just using the wrong commands or what. Any help is greatly appreciated!

    Hi Hayden,
    The trouble is, theDoc doesn't have paragraphs. If you open the InDesign dictionary and look at the document object, you'll see text frames, and you'll see stories, but no paragraphs. To get all of the paragraphs, you'd use something like this:
    set theText to every paragraph of every story
    But getting every paragraph of every story whose applied paragraph style is a specific style is harder to do using a filter ("whose") clause, because it has multiple conditions. Shane can probably do it, but I'm not having much luck. All the same, why bother? InDesign has a perfectly good find text method that will do what you want. Something like this:
    tell application "Adobe InDesign CS3"
    --Clear the find text preferences
    set find text preferences to nothing
    set applied paragraph style of find text preferences to paragraph style "Greeting" of document 1
    tell document 1
    set myFoundItems to find text
    end tell
    end tell
    Thanks,
    Ole

  • Why selecting text and hitting F1 doesn't go to specific help page anymore?

    Hi. Up until a while ago I was able to, while working on some code,  select a particular actionscript component such as a Class, function or  property and hit the F1 key which would immediately bring up Adobe Help  in my internet browser already showing the page relevant to my  selection. For example, if I had selected the word "MovieClip" in my  code and hit F1, the Adobe Help page describing the MovieClip class  would come up, without me having to navigate to it.
    Now (for some weeks actually), it no longer does that. When I hit F1,  Adobe Help comes up in my browser, but opens at a general menu page  regardless of what text I select, which in fact makes selecting text  before hitting F1 redundant anyways.
    Does anyone know anything about this?
    It was so much more convenient before! Now I have to search for what I'm  looking for every time. I'm learning on my own, so I find myself going  to the Help pages quite often. At the end of the day, it sums up to be a  lot of typing and searching and pages to navigate through. Also, it  seems that navigating through the Adobe Help pages is kind of slow which  just makes it even more of a drag.
    I'd appreciate any information on this, or possibly some help in how to get things back to how they were.
    Thanks!

    try to install :
    http://www.adobe.com/support/chc/

  • Paste selected text AND images from a webpage to Pages/Word?

    I'm a new Mac user (also running virtual Windows XP via vmware fusion), and I know next to nothing about my Mac. Please bear with me if this is something that has been answered (I looked, but didn't find a specific answer for my question...it may be here, but I can't find it).
    On a Windows-based PC, all I need to do is select, copy, then paste into a Word document. All text and images would paste. I can't seem to figure out how to do that in Pages or Word (have MS Office for Mac, too).
    Thanks for any help.

    I suppose I was hoping I could do on my Mac, what I did on my Dell...that doesn't appear to be the case.
    Specifically, I'm talking about clicking/dragging to select what I want (including images), opening a Word document then pasting everying, including ALL selected images. More specifically, at sites with game walkthroughs. I prefer to save them to a document and refer to them offline, if I need to. I actually tried it at 2 different sites (one that hosts their own images and one that does not), with the same results.
    While I was waiting for a response (thank you, so much, by the way), I tried again and actually managed to get the first 3 images (of 60+) to paste into Word. There were blank places in Word, but the invisible images were clickable. In Pages, only the text pasted.
    Tried it every which way, but Sunday, LOL, and nothing worked. If it can't be done on my Mac, then I'll just keep using my Dell (I knew there was a reason I decided to keep it) for that sort of thing and then email them to myself...or try installing my MS Office '07 under virtual Windows.
    Thanks, again.

  • Selected Text and Page Navigation

    Okay.
    Have a document that has several artboards in it. (kinda like a multipage document). Each page is similar, but some of the text boxes has variations from page to page. So if I am zoomed in on page 1 to one text box and I select some text, using the type tool, and then hit SHIFT-page down (or page up) to go to the next page, it won't. Switch to a different tool, and it works.
    WHY? Why can't I use a keyboard short cut to jump to another page while in the type tool mode? I don't want to take my hand off the keyboard or move the mouse.
    Suggestions?
    Thanks.

    The Shift Page shortcuts are not coming from the keyboard shortcuts panel. When I try to enter them says ai cannot use that, searching with artboard  was no help either. Tried making an action, btu unfortuantley that did nto work either. I also chcked the system Preference for Keybaord, and could nto find the keyboard shorcut coming fomr there either.
    In summary uopu can use home and end while inside text and the I beam is flashing, btu not page up or page down. That seems to be a hidden comand for goingf to next and previous artboard, so that will lwork without any text on the page.

  • Selecting text and scrolling in Tiger vs. Leopard.

    Please forgive these very basic, verbose, questions.
    I've noticed that Leopard does not allow me to select text the same way that Tiger did. With Tiger I could position the mouse cursor either to the left or to the right of the text, hold down the mouse button and move the cursor across the text. With Leopard I have to place the mouse cursor to the left of the text, click and then hold down the shift key and progessively add to the selection as I move the cursor from left to right. I much prefer the first technique. Is there any way to go back to it?
    Also, scrolling a page in Safari is different. Tiger allowed me to place the cursor on the blue dingus on the right side of the page and hold the mouse key down and draw the dingus up or down. With Leopard I have put the cursor where I want to dingus to go, click and it jumps to that location. Again, I prefer Tiger to Leopard. Any way to restore Tiger's technique?

    What you describe about the scroll bar (it's called the thumb, by the way) happens when you hold the option key down. However, if I hold the option key down, I can't replicate your first behavior.
    I can't imagine your option key is stuck down because you'd be getting all kinds of weird characters when you type.
    There is another thread where someone is having odd behavior like the shift key is held down. We don't seem to be getting anywhere with that one, though.

  • When I want to select text and/or pictures by doubleclicking it doesn't react

    How can I solve this problem?

    Hi
    Please check if the text and image that you are selecting if they are on master page or they are behind some layer.
    Thanks,
    Sanjit

  • Acrobat 9: Selected text and Table

    Hi all expert,
    I am new to Acrobat plug-in development.
    can anybody tell me, how to check selected text is in table?
    plz help!
    Thanks.

    ok,
    suppose if I export document as tagged document .
    is there any way to  identify tables.?
    please help

  • I cannot resize the selected text and the object in Illustrator

    I am unable to resize the text and the object with transform tool. It resizes but half of it does not. and not that much i want.

    Ok so if i write some text and all the words are of different sizes and i have to resize it using the transform tool, i cannot resize it unto the size i want. e.g.. i wrote this text "The Big Bold Sale" all the words are of different sizes and are grouped together, so when i resize it using transform tool all these words are resized differently "The big" becomes big, "bold" becomes little smaller and "sale" is not resized.. the image is attached.

  • Find & Replace the text and apply paragraph style in indesign CS2.

    Hai below script are working in cs4 - cs5.5. i need to run the script in indesign cs2.
    can you please help.
    Main();
    function Main() {
        var foundItem;  
        var doc = app.activeDocument;
        //app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
    app.findTextPreferences.findWhat = "^p";
           //app.findTextPreferences.appliedParagraphStyle = "head";
        var foundItems = doc.findText();
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            foundItem.applyParagraphStyle(doc.paragraphStyles.item("content body indent"), false);
         app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
         var myDocument = app.activeDocument;
    //Clear the find/change text preferences.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    //Set the find options.
    app.findChangeTextOptions.caseSensitive = false;
    app.findChangeTextOptions.includeFootnotes = false;
    app.findChangeTextOptions.includeHiddenLayers = false;
    app.findChangeTextOptions.includeLockedLayersForFind = false;
    app.findChangeTextOptions.includeLockedStoriesForFind = false;
    app.findChangeTextOptions.includeMasterPages = false;
    app.findChangeTextOptions.wholeWord = false;
    //Search the document for the string "copy" and change it to "text".
    app.findTextPreferences.findWhat = "^p";
    app.changeTextPreferences.changeTo = "^p";
    myDocument.changeText();
    //Clear the find/change text preferences after the search.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    abc();
    function abc() {
        var foundItem;  
        var doc = app.activeDocument;
        //app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
    app.findTextPreferences.findWhat = "*";
           //app.findTextPreferences.appliedParagraphStyle = "head";
        var foundItems = doc.findText();
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            foundItem.applyParagraphStyle(doc.paragraphStyles.item("RealEstate"), false);
         app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
         var myDocument = app.activeDocument;
    //Clear the find/change text preferences.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    //Set the find options.
    app.findChangeTextOptions.caseSensitive = false;
    app.findChangeTextOptions.includeFootnotes = false;
    app.findChangeTextOptions.includeHiddenLayers = false;
    app.findChangeTextOptions.includeLockedLayersForFind = false;
    app.findChangeTextOptions.includeLockedStoriesForFind = false;
    app.findChangeTextOptions.includeMasterPages = false;
    app.findChangeTextOptions.wholeWord = false;
    //Search the document for the string "copy" and change it to "text".
    app.findTextPreferences.findWhat = "*";
    app.changeTextPreferences.changeTo = "";
    myDocument.changeText();
    //Clear the find/change text preferences after the search.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    ab();
    function ab () {
        var foundItem;  
        var doc = app.activeDocument;
        app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
        app.findTextPreferences.findWhat = " ^ ";
    app.changeTextPreferences.changeTo = " ";  
        //app.findTextPreferences.appliedParagraphStyle = "head";
        var foundItems = doc.findText();
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            foundItem.applyParagraphStyle(doc.paragraphStyles.item("day"), false);
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
         var myDocument = app.activeDocument;
    //Clear the find/change text preferences.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    //Set the find options.
    app.findChangeTextOptions.caseSensitive = false;
    app.findChangeTextOptions.includeFootnotes = false;
    app.findChangeTextOptions.includeHiddenLayers = false;
    app.findChangeTextOptions.includeLockedLayersForFind = false;
    app.findChangeTextOptions.includeLockedStoriesForFind = false;
    app.findChangeTextOptions.includeMasterPages = false;
    app.findChangeTextOptions.wholeWord = false;
    //Search the document for the string "copy" and change it to "text".
    app.findTextPreferences.findWhat = "^";
    app.changeTextPreferences.changeTo = "";
    myDocument.changeText();
    //Clear the find/change text preferences after the search.
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;

    @s_ashok – you'll find the right methods and properties in the CHM file for InDesign CS2 at:
    http://www.jongware.com/idjshelp.html
    Just a few hints:
    InDesign CS2 does not support GREP search/replace, so every line in your code that points to GREP does not work.
    Further: "app.findTextPreferences" and "app.changeTextPreferences" were "app.findPreferences" and "app.changePreferences" in InDesign CS2. And then there were no "findChangeTextOptions" or any counterpart for that in CS2…
    That should get you running…
    I have no InDesign CS2 installed to debug, so this is all I can say…
    Uwe

Maybe you are looking for

  • Stop auto opening of iphoto

    when i plug my camera to the usb iphoto starts. how can i stop this?

  • SAPscript address name1 and name2 - print on the same line

    I want to print name1 and name2 on the same line in an address on a check. Does anyone know how to do that ? I am usign the ADDRESS SAPscript command.

  • Best photo sharing app

    What does everyone use to share photos online? The Facebook and Flickr apps are iPhone only and really aren't very good on iPad, not sure I believe that Picasa is going to have a very long life, Google Plus is too new. What is the general consensus?

  • Force download video in stead of using the cache ?

    Hello, Does anyone has expierence with the fact that when you connect to an flv file to play video in flash the first time it will download the flv file. But suppose i change the content of the flv file but keep the name the same it will play the pre

  • Adobe will not create PDF files anymore

    I have been using Adobe Acrobat 7.0 on my laptop for years, suddenly it stopped working.  I try to reinstall and it won't activate so I still can't use it..  Why????