DefaultStyledDocument -- Not writing the alignment properly

I am trying to write DefaultStyledDocument on a file. I am not able to write the alignments. Below is the code what I am using.
import javax.swing.text.*;
import javax.swing.text.rtf.*;
import java.io.*;
class RtfSaveAlignment
     public static void main(String argv[])
          RTFEditorKit kit = new RTFEditorKit();
          DefaultStyledDocument doc = new DefaultStyledDocument();
          MutableAttributeSet attr = new SimpleAttributeSet();
          try
               doc.insertString(0, "some text",attr);
          catch (BadLocationException bad) { bad.printStackTrace(); }
          StyleConstants.setAlignment(attr, StyleConstants.ALIGN_CENTER);
          doc.setParagraphAttributes(0, doc.getLength(), attr, false);
          try
               FileOutputStream out = new FileOutputStream("sample.rtf");
               kit.write(out, doc, 0, doc.getLength());
               out.close();
          catch (IOException ioex) { ioex.printStackTrace(); }
          catch (BadLocationException bad) { bad.printStackTrace(); }
          System.out.println((StyleConstants.getAlignment(attr) == StyleConstants.ALIGN_CENTER)?"CENTER":"NOT CENTER");
          System.exit(0);
Please consider this request as very very ... urgent.
Thanks

Ok I wll follow your suggestions.import javax.swing.text.*;
import javax.swing.text.rtf.*;
import java.io.*;
class RtfSaveAlignment
public static void main(String argv[])
RTFEditorKit kit = new RTFEditorKit();
DefaultStyledDocument doc = new DefaultStyledDocument();
MutableAttributeSet attr = new SimpleAttributeSet();
try
doc.insertString(0, "some text",attr);
catch (BadLocationException bad) { bad.printStackTrace(); }
StyleConstants.setAlignment(attr, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), attr, false);
try
FileOutputStream out = new FileOutputStream("sample.rtf");
kit.write(out, doc, 0, doc.getLength());
out.close();
catch (IOException ioex) { ioex.printStackTrace(); }
catch (BadLocationException bad) { bad.printStackTrace(); }
System.out.println((StyleConstants.getAlignment(attr) == StyleConstants.ALIGN_CENTER)?"CENTER":"NOT CENTER");
System.exit(0);
}Can you please suggest something on the above question.

Similar Messages

  • My printer will not detect the alignment page and prints out poorly?

    My printers scanner will not detect the alignment and prints our poorly? Help!

    Please read this post then provide some details.  What printer model? What operating system? Are black and color properly printing on the alignment page?
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • Log4j not writing the llog file

    Hi
    I have a webapplication hosted on WAS,which is not writing the log file.Does anybody know the reason.?
    I have checked the log4j many times.it seems ok.as same file is working in another environment.
    Any help would be appreciated.
    Thanks
    Akash.

    Hi .the problem is solved.i changed the classloading as APPLICATION instead of MODULE in application.xml.
    Thanks.
    Akash.

  • Time achine. Each time I wake up my Mac. it says that I did not eject the disk properly. Do I have to eject the external hard drive before putting the Mac. to sleep?

    Time Machine. Each time I wake up my Mac. it says that I did not eject the disk properly. Do I have to eject the external hard drive each time I put the Mac. to sleep?

    If you do eject or disconnect that external drive before sleep, do you ever get that message?
    Some Drives & chipsets will not work right with sleep, what brand/model is it?

  • Photosmart C4380 printer not detecting the Alignment page

    Can anyone shed any light on this for me please?  The printer has printed the alignment page but when it's placed on the glass it isnt detecting it. It wont let me print anything without completing this.
    Thanks

    Please read this post then provide some details.  What printer model? What operating system? Are black and color properly printing on the alignment page?
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • Field Symbol not writing the values while executing in background.

    Hi,
    In my program i am writing the values of a field symbol to list output.
    write :/ <f_fs_up_excel_wa2>.
    Its writing successfully when i am executing in foreground.
    But when i am executing in background(Submitting the same program as a job)
    its not displaying the values from field-symbol but all the other write statments are getting displayed in the spool.
    Could anybody help me out in this situation and how to handle it?
    Thanks,
    SAM.

    Hmm.  I think the problem is that the field-symbols is blank in background processing, rather than background process has some fault that prevents it being displayed...
    On that basis - how is this field-symbol populated?
    matt

  • Can not get the alignment to happen and load new OfficeJet 7500A

    Just bought Office Jet 7500A 4 in one wife format printer got everything out and ready to go and relized I had plugged in the usb cable un plugged everything and started a gain but to no avail. please help what can I do loaded the software to the connect and it won't read?
    Anything would be most appreciated have a art show to go to this friday!!!!!!!!!!

    Hi,
    Please unplug any USB and remove any Cartridges and the printhead from your printer.
    Turn the printer Off and then On again, follow the on-screen directions.
    Make sure not to insert any printhead or cartridge till being asked to do so,
    If during the steps any part is not being recognized correctly, power cycle the printer
    Please let me know if you may see any progress or if there is any print performed during the alignment.
    As well, if any particular message appears, please let me know the error.
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • File Receiver Adapter is not writing the file?

    Hi All,
    I am having a file to file scenario using NFS as both the source and destination are on server.
    File is getting picked up from server but not reaching the destination.
    In RWB for Receiver channel it only shows <b>Channel active and started correctly.</b>
    In SXMB_MONI  it shows the message scheduled for some later time.
    On reaching that time it tries again and reschedules :(.
    Please guide.
    Regards,
    Sumit

    Sumit,
    Now do one thing, just for check the directory for read/write permission by putting the test file manually on your target directory.
    The porcedure to put a file on server is as shown below:
    1. Save your file in your local machine.
    2. In <b>XI server</b>, enter the tranaction code "<b>SXDA_TOOLS</b>".
    3. In the input screen, enter:
    i) Object Type "DXPROJECT".
    ii) Program Type "BAPI".
    iii) Program "CREATE".
    4. Press Copy (Ctrl+F5) button.
    5. Now, you will get another screen in which you will see 3 blocks called as "Source", "Target" and "Copy with/without conversion".
    6. In Source block, choose the radio button "Presentation Server" and then take F4 help to select your source file. (file which you have saved on your local machine)
    7. In source block select the radio button "Application Server", check the box "Remote server" and take F4 help to select your application server.
    8. In the same block under "File Type" select "P physical file name" and under "File Name" write the path/directory name which you have mentioned in your communication channel along with the file name.
    Example: suppose file name in your Comm Chanel is "<b>demo.xml</b>" and directory path is <b>"/abc/testfiles/XML/</b>", then in step 8 write <b>"/abc/testfiles/XML/demo.xml</b>".
    Note: need not to do any thing in 3rd block.
    After doing all the above, let me know the results.
    Regards,
    Sarvesh
    ****Reward points, if it helpd you.

  • File adapter not writing the file correctly

    Hi,
    I am facing an issue where the file created on the destination is not with the correct data. eventhough the payload that was sent out from XI to the adapter is correct.
    Issue was with a mltiple element which was written once eventhough the payload shows multiple existance.
    we had changed the occurance of that element from 1 to unbounded.
    If anyone has any idea do let me know
    Regards
    Nikhil

    I tried to redo the config objects but still the same issue is there. anyone has any idea

  • I'm trying to work with some links in Illustrator, but the program is not updating the artwork properly. What am I doing wrong?

    It's not working the update-link system in my Adobe Illustrator CC installation.

    Moving to Illustrator forum.
    Regards,
    Romit Sinha

  • BP_CONFIRM does not triggers the event properly from call list

    Hi expert,
    We have upgrading CRM 5 to 7.
    The issue is. In the IC_AGENT role. When i got to call list and select a call. The corresponding bp is automatically conformed.
    But then when i go to Account identification navigation link i can only see the bp confirmed. the vehicle  info of the BP are not displayed the view remains the same. normally it displays the vehicle details in the result view.
    If i directly search for a BP and conform it all the vehicle detail are displayed in the result views.
    It happens only when a BP is automatically conformed by selecting from the call list.
    But in both the cases the Method  "CL_CRMCMP_B_CUCOBUPA_IMPL->BP_CONFIRM" is triggered ( it is a customer control in CRMCMP_BPIDENT/CuCoBuPa )
    the difference i can find is.
    if i conform a bp manually from the account identification screen. the CL_ICCMP_AU_VEHISEARCH_IMPL->IF_CRM_IC_EVENT_LISTENER~HANDLE_EVENT is triggered. ( which is inside the "ICCMP_AUTO_VEHI/VEHISearch" ) which displays the required view.
    but when the same BP_CONFIRM is triggered automatically from the call list management view it is not triggering CL_ICCMP_AU_VEHISEARCH_IMPL->IF_CRM_IC_EVENT_LISTENER~HANDLE_EVENT. ( which is inside the "ICCMP_AUTO_VEHI/VEHISearch" ).
    so i can see the difference in the event listeners of the 2 process.
    below is the piece of code which triggers the event. it is in the method "CL_CRMCMP_B_CUCOBUPA_IMPL->BP_CONFIRM" d ( it is a customer control in CRMCMP_BPIDENT/CuCoBuPa )
    raise event BPConfirmed and/or CPConfirmed
        IF lv_bp_confirm EQ abap_true.
          CLASS cl_crm_ic_services DEFINITION LOAD.
          CREATE OBJECT event.
          event->set_name( if_crm_ic_events_con=>gc_bpconfirmed ).
          event_srv = cl_crm_ic_services=>get_event_srv_instance( ).
          event_srv->raise( event ).
        ENDIF.
    Can any one help me how to register  the event or trigger the CL_ICCMP_AU_VEHISEARCH_IMPL->IF_CRM_IC_EVENT_LISTENER~HANDLE_EVENT is triggered. ( which is inside the "ICCMP_AUTO_VEHI/VEHISearch" )
    when i click on call list.
    thanks in advance
    chella.

    Hi expert,
    We have upgrading CRM 5 to 7.
    The issue is. In the IC_AGENT role. When i got to call list and select a call. The corresponding bp is automatically conformed.
    But then when i go to Account identification navigation link i can only see the bp confirmed. the vehicle  info of the BP are not displayed the view remains the same. normally it displays the vehicle details in the result view.
    If i directly search for a BP and conform it all the vehicle detail are displayed in the result views.
    It happens only when a BP is automatically conformed by selecting from the call list.
    But in both the cases the Method  "CL_CRMCMP_B_CUCOBUPA_IMPL->BP_CONFIRM" is triggered ( it is a customer control in CRMCMP_BPIDENT/CuCoBuPa )
    the difference i can find is.
    if i conform a bp manually from the account identification screen. the CL_ICCMP_AU_VEHISEARCH_IMPL->IF_CRM_IC_EVENT_LISTENER~HANDLE_EVENT is triggered. ( which is inside the "ICCMP_AUTO_VEHI/VEHISearch" ) which displays the required view.
    but when the same BP_CONFIRM is triggered automatically from the call list management view it is not triggering CL_ICCMP_AU_VEHISEARCH_IMPL->IF_CRM_IC_EVENT_LISTENER~HANDLE_EVENT. ( which is inside the "ICCMP_AUTO_VEHI/VEHISearch" ).
    so i can see the difference in the event listeners of the 2 process.
    below is the piece of code which triggers the event. it is in the method "CL_CRMCMP_B_CUCOBUPA_IMPL->BP_CONFIRM" d ( it is a customer control in CRMCMP_BPIDENT/CuCoBuPa )
    raise event BPConfirmed and/or CPConfirmed
        IF lv_bp_confirm EQ abap_true.
          CLASS cl_crm_ic_services DEFINITION LOAD.
          CREATE OBJECT event.
          event->set_name( if_crm_ic_events_con=>gc_bpconfirmed ).
          event_srv = cl_crm_ic_services=>get_event_srv_instance( ).
          event_srv->raise( event ).
        ENDIF.
    Can any one help me how to register  the event or trigger the CL_ICCMP_AU_VEHISEARCH_IMPL->IF_CRM_IC_EVENT_LISTENER~HANDLE_EVENT is triggered. ( which is inside the "ICCMP_AUTO_VEHI/VEHISearch" )
    when i click on call list.
    thanks in advance
    chella.

  • Not getting the output properly

    i am entering the command, not get the total out put
    see the output what i am getting.
    SQL> select dbms_metadata.get_ddl ('TABLESPACE','SYSTEM') FROM DUAL;
    DBMS_METADATA.GET_DDL('TABLESPACE','SYSTEM')
    CREATE TABLESPACE "SYSTEM" DATAFILE
    '/u0101/oradata/GFSSS1/system01.dbf' S
    SQL>
    can u please suggest me , which perameters i have to set.

    i want ouput from my machine, not from OEM.
    see the output message,
    SQL> set pages 1200
    SQL> set lines 120
    SQL> select dbms_metadata.get_ddl ('TABLESPACE','SYSTEM') FROM DUAL;
    DBMS_METADATA.GET_DDL('TABLESPACE','SYSTEM')
    CREATE TABLESPACE "SYSTEM" DATAFILE
    '/u0101/oradata/GFSSS1/system01.dbf' S
    SQL>

  • On my C4795, when I put a new cartridge in, it will not print the alignment page properly.

    Page only prints about 20-25% of normal.  Then, scan doesn't recognize page.  Solutions don't address this.  Tried another cartridge, same thing.

    We need to know what Mac you are using and what version of OS X, then we can get your question transferred to the correct forum.

  • Not writing the file second time

    hi Experts
    can anybody tell me after executing this code on windows the value is not written second time to file
    the code goes like this
    import java.util.*;
    import java.io.*;
    import java.net.*;
    public class Agent
         public static void main(String args[])
              File script=null;
              File outputFile=null;
              BufferedReader check=null;
              try
                   check = new BufferedReader(new FileReader("checkThreshold.txt"));
                   String checkStr;
                   while((checkStr=check.readLine())!=null)
                        checkStr=checkStr.trim();
                        //System.out.println(checkStr);
                        StringTokenizer st=new StringTokenizer(checkStr);
                        String commandStr=st.nextToken();
                        String paramStr=st.nextToken();
                        //String wThresholdStr=st.nextToken();
                        float wThreshold=Float.parseFloat(st.nextToken());
                        //String mThresholdStr=st.nextToken();
                        float mThreshold=Float.parseFloat(st.nextToken());
                        //String cThresholdStr=st.nextToken();
                        float cThreshold=Float.parseFloat(st.nextToken());
                        script= new File(System.getProperty("java.io.tempdir"),"script.vbs");
                        outputFile= new File(System.getProperty("java.io.tempdir"),"outputFile.txt");
                        PrintWriter writer=new PrintWriter(new FileWriter(script,false));
                        //System.out.println("command is:"+commandStr+" paramis:"+paramStr+"wThresholdStr:="+wThresholdStr+" mThresholdStr:"+mThresholdStr+"cThresholdStr:"+cThresholdStr);
                             writing a script for getting value and then comparing then
                        writer.println("Dim Wsh,cmd\n"+
                             "Set Wsh = Wscript.CreateObject(\"Wscript.Shell\")\n"+
                             "Wsh.Run(\"cmd.exe\")\n"+
                             "WScript.Sleep 1000\n"+
                             "Wsh.SendKeys \"wmic /output:"+outputFile+" path "+commandStr+" get/value{ENTER}\"\n"+
                             "WScript.Sleep 1500\n"+
                             "Wsh.SendKeys \"exit{ENTER}\"\n");     
                        writer.close();
                        /***********executing the script************/
                        Process p=Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", "\""+script+"\""});
                        int exitValue=p.waitFor();
                           BufferedReader in = new BufferedReader(new FileReader(outputFile));
                        String str;
                        int cnt=0;
                        while((str=in.readLine())!=null)
                             str=str.trim();
                             String tempStr="";
                             StringBuffer buffer=new StringBuffer();
                             for(int i=0;i<str.length();i+=2)
                                  buffer.append(str.charAt(i));
                             tempStr=buffer.toString();
                             if(tempStr.startsWith(paramStr))
                                  StringTokenizer token=new StringTokenizer(tempStr,"=");
                                  token.nextToken();
                                  float value=Float.parseFloat(token.nextToken());
                                  if(value>=cThreshold)
                                       System.out.println("critical");
                                  else if(value<cThreshold && value>=mThreshold)
                                       System.out.println("major"+value);
                                  else if(value<mThreshold && value>=wThreshold)
                                       System.out.println("warning"+value);
                                  else
                                       System.out.println("normal"+value);                         
                        cnt++;
                        System.out.println(cnt);
                        script.delete();
              }catch(Exception e)
                        System.out.println(e);
    }

    I tried to redo the config objects but still the same issue is there. anyone has any idea

  • Dreamweaver not displaying text alignment properly

    Hi,
    I'm working on a site where I want a Div with a background image to align right of the text. It shows up correctly in IE, Firefox, Opera, and Safari, but not in Dreamweaver CS4 while I'm working on it.
    Live page example: http://www.libertywebmarketing.com/test/sonic/CT-Audio-Mastering.html
    Screenshot of Opera:
    Screenshot of DW CS4:
    Any ideas?
    Thanks.
    Fitz21

    Thanks Nancy.
    The image on the right is a background image of a Div, so I don't understand what I did wrong (if anything). Shouldn't the text appear to its left, just as if it were a table with a background image?
    The link you posted will be helpful though for something else I have to do. Thank you.
    Any other ideas?
    Fitz21

Maybe you are looking for