DefaultStyledDocument trim problem

Hi all,
JTextPane pane = new JTextPane();
DefaultStyledDocument temp = new DefaultStyledDocument();
temp = (DefaultStyledDocument) pane.getDocument();
is there any way to trim the document, like string.
I wnat to trim the spaces and new empty lines in the end of the document.
I can getText from document and trim it but the problem is I am loosing style of the document.
any idea ???
thanks

Element e = temp.getDefaultRootElement();
Element e2;
String str;
int length;
int len = e.getElementCount();
boolean done = false;
for(int = len-1;i>=0, done == false;i--) {
        done = true;
     e2 = e.getElement(i);
     if(e.isLeaf()) {
          length = e.getEndOffset() - e.getStartOffset();
          str = temp.getText(e.getStartOffset(), length);
          if(str.trim().equals("")) {
               temp.remove(e.getStartOffset(), length);
               temp.insertString(e.getStartOffset(), str.trim(), e.getAttributes());
                        done = false;
}That should do it, but it's not something you'd want to run regularly.
But then again, if you're trying to do this repeatedly, then why aren't you simply trimming the text before it is added to the document?

Similar Messages

  • A DefaultStyledDocument saving problem

    Hello there:
    I used a JTextPane to support richtext in my application. when I finish typing in the textpane I want the content saved in a vector, and clean the text pane. Code is as below. Now I have a problem: the doc is a reference so when I " setText("") ", the content of doc is gone, nothing is saved in the vector.
    I think I need to create a new Document and copy the content of the old one. But I don't know how to do it. Anyone have any idea?
    Thanks a lot,
    Sway
    /*---code: save to a vector ----*/
    DefaultStyledDocument doc = (DefaultStyledDocument)textPane.getDocument();
    textPane.setText("");
    vec.addElement(doc);

    thank you, camickr:
    The reason why I wanted to save the references into a vector is I want the users to do the repeative input , each time they save the existing documents before they can input the new ones. Later all these documents will be saved in a persistent file in a sequential manner.
    I didn't realize I could use the way you suggested in the reply so I use "setText", which is awkward, and obviously, didn't work.
    Thank you again,
    Sway

  • String.trim() problem.

    Hi
    I have an ascii file that I parse, the first like is
    " hello there "
    When I do a trim() on the String. It returns:
    " hello there "
    If I do:
    Character.isSpaceChar(str.charAt(0))
    It returns true.
    If I go into into the file using a text editor and delete the spaces and replace them, the trim() work.
    It seems that the characters are not white spaces, although isSpaceChar returns true.
    Any ideas?
    Thanks
    George

    You might use regex and the space categories "\\p{IsZs}" or "\\p{Zs"}
    [url http://www.fileformat.info/info/unicode/category/Zs/list.htm]http://www.fileformat.info/info/unicode/category/Zs/list.htm
    [url http://unicode.org/Public/UNIDATA/UCD.html#General_Category_Values]http://unicode.org/Public/UNIDATA/UCD.html#General_Category_Values
    [url http://www.fileformat.info/info/unicode/category/index.htm]http://www.fileformat.info/info/unicode/category/index.htm
    Sun's Regular Expression Tutorial for Java
    Regular-Expressions.info
    str = str.replaceAll("^[\\s\\p{Zs}\\p{Zl}\\p{Zp}]*\\b(.*)\\b[\\s\\p{Zs}\\p{Zl}\\p{Zp}]*", "$1");seems like it might work, but it might also be overkill.

  • Load and Trim Problems with IdeaTab A1000

    Lenovo IdeaTab A1000 16GB at work was a terrible device. Having spent two weeks hanging software. I had to give a warranty repairs.
    After a week of warranty repairs, the device worked for five hours and again hung software ...
    I'm beginning to think that was wrong with the choice of the device.

    I have to try this and I will let you.
              Thanks
              Jon Eagles wrote:
              > All,
              >
              > We have a simple servlet which looks up an RMI object from JNDI and invokes
              > one of its methods in a loop. The RMI object is the HelloClusterImpl
              > example provided by WebLogic. The servlet basically copies the code from
              > the HelloClusterClient. In the cluster property file, our load algorithm is
              > setup to be round-robin. We are using IIS as our web server. If we start
              > up both servers in the cluster and then use another machine as our client to
              > call the HelloClusterClient, we see that the calls to HelloClusterImpl
              > alternate between the two clustered servers. In fact, it is done perfectly
              > at 50% for each server. When we run the servlet from with the client's
              > browser, however, it seems as if which ever server in the cluster that
              > receives the servlet request then takes 100% of the calls to
              > HelloClusterImpl and there is never any alternating. Although we can verify
              > that different servers in the cluster receive the servlet request, it seems
              > as if there is never any altering between the servers during the method
              > invocations on the HelloClusterImpl servant. Does this seem right?
              > Shouldn't there be alternating between the servers? Any help would be
              > greatly appreciated.
              >
              > Thanks,
              >
              > -Jon
              

  • Trimming - I want to delete various segments, keeping the remainder

    QT 7 Pro Trimming problem -- I have a long movie clip, of which I want to keep various short bits. It is possible to simply delete segments that I don't want so I am left with only the bits that I DO want?  This interface allows me to only select what I want to keep, and in doing so deletes the rest -- of which is footage I want to keep in addition to my initial selection.  QT 7 on my older iMac (OS 10.4.8) can do this - you select a segment by moving two little knobs to the start point and end point of the segment.  Deleting it still leaves me with the rest of the movie. I keep deleting segments I don't want, and end up with only that that I do want.  Is this not possible anymore on QT 7 Pro my newer MBPro? 

    QuickTime Player Pro has worked the same on any machine or OS for the last (nearly) seven years. That's how long version 7 has been available. What you did in Tiger still works the same in Lion.
    The "two little knobs" are known as in and out markers and when you set them, either with the keyboard shortcuts i and o keys, drag while holding the shift key or drag each of the markers you've made a "selection".
    A selction can be something you want to keep or something you want to remove. If you're trying to remove (trim) you would make selections of what you wanted to delete which would leave you with only what you wanted to keep.
    If you are running Snow Leopard or Lion be aware that it includes QuickTime X or 10.1 and it also has a trim feature. It doesn't edit the same way as QuickTime Player 7 Pro and its version of trimming would require you to save the file each time you made an edit.
    Make sure you're using QuickTime Player 7 Pro and not QuickTime Player 10 or 10.1.

  • I have a clip with synchronized audio. When I trim a section of video it does not trim the audio. How do I trim both video and audio so that the clip remains in sync?

    Why is FCPX not allow me to cut both video and audio tracks at the same time?
    My separate synchronized audio does not trim when I trim the video. They are connected and synchronized.

    fulei wrote:
    The audio track does not edit along with the video. They go out of sync
    Sounds like a different problem than your trim problem in the first post. If your problem is they drift out of sync, we'd need to knoow more about the project and clip properties – including how the audio file you're syncing to was created.
    Russ

  • Import parameter formatting for BAPI

    Hi
    I am using BAPI_SALESORDER_GETLIST to get the sales orders.
    When i hardcode the values as follows, it works
    importParams.put("CUSTOMER_NUMBER", "0000001000");
    importParams.put("SALES_ORGANIZATION","1000");
    Now i have a screen to capture the input and passes it to the importParams. But no result comes out.
    JSP Code:
    <hbj:textView id="c1"  text= "customer" />
    <hbj:inputField id="customer" type="string" maxlength="100" />
    <hbj:textView id="c2"  text= "sales Organization" />
    <hbj:inputField id="sales" type="string" maxlength="100" />
           <hbj:button id="oKbutton"
                   text="OK"
                   onClick="myClick"
                   design="EMPHASIZED"
                   width="100"
                   >
                   <% myFormId.setDefaultButton(oKbutton); %>
           </hbj:button>
    OnClick Code:
              public void onMyClick(Event event) throws PageException {
                   Component c = this.getComponentByName("customer");
                   if ( c instanceof InputField )
                     customerNo = ((InputField) c).getString().toString();
                   Component d = this.getComponentByName("sales");
                   if ( d instanceof InputField )
                        salesOrg = ((InputField) d).getString().toString();
    Assignment Code:
    I have declared them as Strings at the Top
    String customerNo = "";
    String salesOrg = "";
    importParams.put("CUSTOMER_NUMBER", customerNo.trim() );
                        importParams.put("SALES_ORGANIZATION", salesOrg.trim());
    Problem:
    Now even if i type "0000001000" and "1000" as values in the input field, there is no result.
    I debugged the onClick event and confirmed that the values are being passed from the first page properly as STRINGS. Both these paramters are strings. So i maintained the leading ZEROS.
    Any Help would be appreciated.
    Murali.

    Hi
    Can anyone Help me out.

  • Only OpenDirectory admins can see freebusy

    I'm running OSX Server 10.5.6, and have an iCal instance running with users set up through Open Directory. However, only people set up as admins in Open Directory are able to see freebusy information in their clients. I'm guessing that freebusy access is restricted to a specific user group in Open Directory, but I don't know what that group would be.
    Clients are running Thunderbird with a modified version of the Lightning plugin from http://www.scalableogo.org/about/overview.html.
    Any ideas?

    It looks like a kind of security trimming. First of all, would you issue Set-FastSearchSecurityLogLevel command to increase a log level in attempt to identify if it is security trimming problem (as it looks like)?
    Here is a command description:
    http://technet.microsoft.com/en-us/library/ff393815.aspx

  • MacBook Pro 17" compatibility with SSD Drive

    Hi everyone
                   Please Help!!!!   I have a MacBook Pro 6,1 Mid 2010 2.66 core i7 memory 8 gb.   I want to put in a SSD hard drive the Samsung 840 Pro 256 gb
    I have tried to research so much that I am more confused as to it compatibility  I would just like a simple change out I am not a tech guru but having read so many different comments online about its works fine,it doesn't work ,os x firmware problems,trim problems,this that and the other etc.etc. is there anyone that has a 2010 model like mine that can tell me if the Samsung will work without having to go crazy trying to make it work. Because I have read that it is a great SSD but is it great for my MacBook model and year without having to hassle tweaks,changes,or problems because it not really the right drive for my MacBook .
                  Thank in Advance  Randy.    

    Install/upgrade RAM or storage drive in Mac's
    Most commonly used backup methods
    How to erase and install Snow Leopard 10.6
    http://www.mactrast.com/2011/07/how-to-enable-trim-support-for-all-ssds-in-os-x- lion/

  • ReFind question: is it possible to bridle this function? :)

    Usually I have to make a loop to find a word using
    ReFind(NoCase), changing start position inside on every step.
    The question is:
    is it possible to "bridle" ReFind function in order make it
    return ALL occurences AT ONCE, using some special regular
    expression.
    For instance, ourString is "Our Rob is a robber of the Robson
    bank"
    and I want to find all inclusions of "rob"
    I wish if
    ReFindNoCase((something, but 'rob')*(rob)(something, but
    'rob')*)*, ourString, 1, true)
    would return all positions of 'rob' occurence here in pos and
    len arrays....

    not sure exactly what you are asking for, but, this is how,
    in my support trouble ticket app, i return details of a user query
    of a keyword from the knowledge base. in this example, it will
    highlight all instances of the "keyword" in either the problem
    field or the solution field. just make sure you have a session var
    to start of with....
    <cfif IsDefined("SESSION.USERFILTER.KEYWORD")>
    <cfset replaceWhat = SESSION.USERFILTER.KEYWORD />
    <cfset problem = trim(rsGetTicket.Problem) />
    <cfset solution = trim(rsGetTicket.resolution) />
    <cfloop list="#replaceWhat#" index="what" delimiters="
    ">
    <cfset problem = replaceNoCase(problem,what," <span
    style=""background:##6fff68;""> "&what&"</span>
    ","ALL")>
    <cfset problem = replaceNoCase(problem,what," <span
    style=""background:##6fff68;""> "&what&"</span>
    ","ALL")>
    <cfset solution = replaceNoCase(solution,what," <span
    style=""background:##6fff68;""> "&what&"</span>
    ","ALL")>
    <cfset solution = replaceNoCase(solution,what," <span
    style=""background:##6fff68;""> "&what&"</span>
    ","ALL")>
    </cfloop>
    <cfoutput>#ParagraphFormat(trim(problem))#</cfoutput></p>
    <hr width="100%" size="1" noshade>
    <p align="left"><cfif #rsGetTicket.Complete# IS NOT
    "0">Solution:<br>
    <cfoutput>#ParagraphFormat(trim(solution))#</cfoutput><br>
    <br>
    Tech:
    <cfoutput>#rsGetTicket.CompletedBy#</cfoutput><cfelse>Solution
    for this Issue has not been satisfactorily reached. <br>
    If you have this issue, please submit a <a
    href="sendtt.cfm">trouble
    ticket</a>.<br>
    </cfif></p></cfif>

  • Trim Mark problem. CS5 Any suggestions?

    I am setting out A4 front and back covers as one piece of (A3+bleed) artwork to be reproduced by digital printing. After printing, the covers will be trimmed on four sides then wire bound.
    I set up artwork with covers side by side with 10mm in centre to allow 5mm trim for each spine. My problem is that Illustrator CS5 adds trims on the proof which do not include a facility to specify centrefold trims or even a centreline. AI assumes all artwork will be an single rectangle and only puts trims on the four corners.
    I can create two covers as two separate pieces of artwork with suitable bleed and trims, but then I must proof front and back separately and the printer must re-position each cover side by side arranging trims with his pre-press software. That is inefficient.
    I simply want to hand over a facsimile proof and a complete .pdf fiIe with correct trims. I tried drawing the spine trims I required, but AI ignored them for proofing, even with the desk top enlarged to accommodate the trim marks. The Print dialogue box trims take priority. Has Adobe missed a trick here or am I overlooking a set-up requirement?
    I considered taking the artwork into InDesign but ID also treats my artwork as one page with or without a centrefold, according to how I specify the pages.
    But for the fold facility, the ID Print dialogue behaves the same as AI, as you might expect.
    Can anyone offer suggestions other than the separate artwork option I have described?

    Dear TerraAustralis,
    I work in CS5 and I am trying to create trim marks so that I can manually adjust it after and create more of them since I have a multiple itmes to trim.
    I get an error message when I try to create the mark:
    I have a rectangle with or with stroke or fill (it does the same error), I selct Object-Trim marks
    and I get this: <The filter cannot complete because of an unknown error>
    NESS
    what can I do to be able to edit the marks without making them all manually like before...
    since the Crop marks command does not allow us to manipulate the marks?
    Thank you in advance for your help.
    cc

  • Trim Mark Problem. AI & ID CS5. Any Suggestions?

    I am setting out A4 front and back covers as one piece of (A3+bleed) artwork to be reproduced by digital printing. After printing, the covers will be trimmed on four sides then wire bound.
    I set up artwork with covers side by side with 10mm in centre to allow 5mm trim for each spine. My problem is that Illustrator CS5 adds trims on the proof which do not include a facility to specify centrefold trims or even a centreline. AI assumes all artwork will be an single rectangle and only puts trims on the four corners.
    I can create two covers as two separate pieces of artwork with suitable bleed and trims, but then I must proof front and back separately and the printer must re-position each cover side by side arranging trims with his pre-press software. That is inefficient.
    I simply want to hand over a facsimile proof and a complete .pdf fiIe with correct trims. I tried drawing the spine trims I required, but AI ignored them for proofing, even with the desk top enlarged to accommodate the trim marks. The Print dialogue box trims take priority. Has Adobe missed a trick here or am I overlooking a set-up requirement?
    I considered taking the artwork into InDesign but ID also treats my artwork as one page with or without a centrefold, according to how I specify the pages.
    But for the fold facility, the ID Print dialogue behaves the same as AI, as you might expect.
    Can anyone offer suggestions other than the separate artwork option I have described?

    TerraAustralis wrote:
    I can create two covers as two separate pieces of artwork with suitable bleed and trims, but then I must proof front and back separately and the printer must re-position each cover side by side arranging trims with his pre-press software. That is inefficient.
    Have you asked your printer about this?  I'm a printer and if you gave me a file laid up on a page with your trim marks  from Illustrator the first thing I'd do it place it in Indesign to strip them off and give me individual pages so I could impose it with my pre press software! 
    Check first...Adobe hasn't missed a trick, it's how the printing world expects it's files.

  • Problem with trimmed project

    The project in Premiere Pro CC for Mac was trimmed by project mahager, then when I open trimmed project, clips in sequence was in nonexistent part of original video file.
    Like this:
    What is that? How can I fix it?
    thank you in advance.
    Yermek

    This is a problem I have from time to time with Trimmed Projects.  Even though the media is there, for some reason Premiere can't see it.  It's maddening because it's very hard to duplicate and thus troubleshoot.  But when it happens, there's no sensible explanation.
    Our discussion on this problem is here:
    Re: Trimmed Project sequence not working
    Here's one thing you can try that sometimes works:
    1. take all your media out of the trimmed project folder and put it in a different folder somewhere else
    2. launch the trimmed project
    3. the offline window comes up automatically with a list of missing clips. UNCHECK the align timecode box and manually reconnect all the trimmed clips.
    4. zebra stripes gone. sequence plays.

  • Problem with sql TRIM in PL/SQL package in version 10.1.3.3

    I'm getting invalid token on the trim functions in the following function. The package compiles ok in TOAD, and this package worked fine in the previous version of jdeveloper I was using--10.1.3
    FUNCTION stu_pidm (
    p_profile_name IN VARCHAR2
    RETURN NUMBER
    IS
    v_pidm NUMBER;
    BEGIN
    BEGIN
    SELECT s.szbstdn_pidm
    INTO v_pidm
    FROM szbstdn s
    WHERE trim(s.szbstdn_profile_name) = trim(p_profile_name);
    EXCEPTION
    WHEN OTHERS THEN
    RETURN NULL;
    END;
    RETURN v_pidm;
    END;

    Sorry for confusion, version of OC4J does not really meter, but jdk does. It happened that in the case where everything OK (OC4J 10.1.3.1.0) I accidentally used jdk 1.5. Now I tried both (OC4J 10.1.3.1.0 and OC4J 10.1.3.2.0) with j2sdk1.4.2_14 (besides I tried j2sdk1.4.2_09 and _08) and j2sdk1.5.0_06.
    With JDK 1.5 everything is OK and with JDK 1.4 we have a problem, described in the previous posting. I believe now I should reformulate my initial question:
    Is it possible to configure OC4J 10.1.3 running under j2sdk1.4.2_14 to force Thread Context ClassLoader to behave similar to OC4J 10.1.3 under j2sdk1.5.0_06? If yes, how we could do it?
    Thanks

  • Problem with trimming file

    Hi
    I have an .mp4 file that I want to trim using QuickTime X, it is giving me the following message when I try to save the trimmed file:
    "The document "NAME OF FILE" could not be saved as "NAME OF FILE". An invalid sample description was found in the movie."
    Please help I really want to get my work done. What can I do?
    (Any other options than using iMovie?)

    Could you please tell me what to do more simply?
    I'm saying that the modal message you are getting seems to indicate the data content in your movie does not appear to match what the file container says it is. This could mean that the file is corrupted or that someone has made manual modifications of some sort that the QT X Player does not like.
    Since an MOV container is generic and may contain any valid combination of audio and video data, I was simply wondering if you could re-save the the movie to an MOV file container before attempting to edit it in the QT X Player. This operation does not require the data to be re-compressed and may satisfy whatever problem the player thinks you have with the file. As an alternative, you could try editing the file using the MPEG Streamclip application which, if the source data is really MPEG4/AAC or H.264/AAC, will allow you to save the trimmed data to either and MP4 or MOV file container if that is a matter of any great importance to you.

Maybe you are looking for

  • ComboBox - Setting Selected Values from data

    I am running into a problem in Flex 3 that seems to be different from Flex 2. Maybe someone can help. I have a function for setting a combobox selected item for a location for a value when the titlewindow completes loading. The value is a prior value

  • Urgent : doubt on gui_download

    hi guys, i am using gui_download to download the details into a local file .. when i am downloading into the local file . the matnr containing so many zeros in front when i download into a text file. but my problem is when i download into excel the m

  • Feedback about glitches, misbehaviors errors, missing features, bugs

    I couldn't find a thread where I could submit feedback about glitches, misbehaviors errors, missing features, bugs (and things of that nature) encountered when using Edge and needed a place where I could collect them writing about them as they happen

  • Usb (#3) not longer working?

    Regardless of what device I plug into the third usb port, nothing seems to work. I just want to make sure I didn't miss something and maybe disable or turn it off. All other ports are working normal. I'm running Lion and Windows 7 in Boot Camp and th

  • Flash mx 2004 to Flash 8

    Hi, I have a flash header that I created for my site using flash mx 2004. But I have recently upgrade to flash 8. If I try and open up the header file in flash 8, the document is all disfigured and then timelines etc are all messed up. Is there anywa