JtextPane and Document

Hello,
I Have a Big problem using JTextPane, I'm trying to put some text in it.
But I want to indent it, (slide to the right)
so I use
StyleConstants.setLeftIndent(r, 15f); I had declare every thing necessary before and after but the setLeftIndent method seems do nothing?
could ya help me????

oh it's ok I succeeded using...Maybe you could post your code as it might benefit other who have a quesiton on the same topic.

Similar Messages

  • Problem with JTextPane and StateInvariantError

    Hi. I am having a problem with JTextPanes and changing only certain text to bold. I am writing a chat program and would like to allow users to make certain text in their entries bold. The best way I can think of to do this is to add <b> and </b> tags to the beginning and end of any text that is to be bold. When the other client receives the message, the program will take out all of the <b> and </b> tags and display any text between them as bold (or italic with <i> and </i>). I've searched the forums a lot and figured out several ways to make the text bold, and several ways to determine which text is bold before sending the text, but none that work together. Currently, I add the bold tags with this code: (note: messageDoc is a StyledDocument and messageText is a JTextPane)
    public String getMessageText() {
              String text = null;
              boolean bold = false, italic = false;
              for (int i = 0; i < messageDoc.getLength(); i++) {
                   messageText.setCaretPosition(i);
                   if (StyleConstants.isBold(messageDoc.getCharacterElement(i).getAttributes()) && !bold) {
                        bold = true;
                        if (text != null) {
                             text = text + "<b>";
                        else {
                             text = "<b>";
                   else if (StyleConstants.isBold(messageDoc.getCharacterElement(i).getAttributes()) && bold) {
                        // Do nothing
                   else if (!StyleConstants.isBold(messageDoc.getCharacterElement(i).getAttributes()) && bold) {
                        bold = false;
                        if (text != null) {
                             text = text + "</b>";
                        else {
                             text = "</b>";
                   try {
                        if (text != null) {
                             text = text + messageDoc.getText(i,1);
                        else {
                             text = messageDoc.getText(i, 1);
                   catch (BadLocationException e) {
                        System.out.println("An error occurred while getting the text from the message document");
                        e.printStackTrace();
              return text;
         } // end getMessageText()When the message is sent to the other client, the program searches through the received message and changes the text between the bold tags to bold. This seems as if it should work, but as soon as I click on the bold button, I get a StateInvariantError. The code for my button is:
    public void actionPerformed(ActionEvent evt) {
              if (evt.getSource() == bold) {
                   MutableAttributeSet bold = new SimpleAttributeSet();
                   StyleConstants.setBold(bold, true);
                   messageText.getStyledDocument().setCharacterAttributes(messageText.getSelectionStart(), messageText.getSelectionStart() - messageText.getSelectionEnd() - 1, bold, false);
         } //end actionPerformed()Can anyone help me to figure out why this error is being thrown? I have searched for a while to figure out this way of doing what I'm trying to do and I've found out that a StateInvariantError has been reported as a bug in several different circumstances but not in relation to this. Or, if there is a better way to add and check the style of the text that would be great as well. Any help is much appreciated, thanks in advance.

    Swing related questions should be posted in the Swing forum.
    Can't tell from you code what the problem is because I don't know the context of how each method is invoked. But it would seem like you are trying to query the data in the Document while the Document is being updated. Try wrapping the getMessageText() method is a SwingUtilities.invokeLater().
    There is no need to write custom code for a Bold Action you can just use:
    JButton bold = new JButton( new StyledEditorKit.BoldAction() );Also your code to build the text String is not very efficient. You should not be using string concatenation to append text to the string. You should be using a StringBuffer or StringBuilder.

  • JTextPane and highlighting

    Hello!
    Here's what I'm trying to do: I have a window that needs to display String data which is constantly being pumped in from a background thread. Each String that comes in represents either "sent" or "recieved" data. The customer wants to see sent and recieved data together, but needs a way to differentiate between them. Since the Strings are being concatinated together into a JTextPane, I need to highlight the background of each String with a color that represents whether it is "sent" (red) or "recieved" (blue) data. Should be easy right? Well, not really...
    Before I describe the problem I'm having, here is a small example of my highlighting code for reference:
         private DefaultStyledDocument doc = new DefaultStyledDocument();
         private JTextPane txtTest = new JTextPane(doc);
         private Random random = new Random();
         private void appendLong() throws BadLocationException {
              String str = "00 A9 10 20 20 50 10 39 69 FF F9 00 20 11 99 33 00 6E ";
              int start = doc.getLength();
              doc.insertString(doc.getLength(), str, null);
              int end = doc.getLength();
              txtTest.getHighlighter().addHighlight(start, end, new DefaultHighlighter.DefaultHighlightPainter(randomColor()));
         private Color randomColor() {
              int r = intRand(0, 255);
              int g = intRand(0, 255);
              int b = intRand(0, 255);
              return new Color(r, g, b);
         private int intRand(int low, int hi) {
              return random.nextInt(hi - low + 1) + low;
         }As you can see, what I'm trying to do is append a String to the JTextPane and highlight the new String with a random color (for testing). But this code doesn't work as expected. The first String works great, but every subsequent String I append seems to inherit the same highlight color as the first one. So with this code the entire document contents will be highlighted with the same color.
    I can fix this problem by changing the insert line to this:
    doc.insertString(doc.getLength()+1, str, null);With that change in place, every new String gets its own color and it all works great - except that now there's a newline character at the beginning of the document which creates a blank line at the top of the JTextPane and makes it look like I didn't process some of the incomming data.
    I've tried in veign to hack that newline character away. For example:
              if (doc.getLength() == 0) {
                   doc.insertString(doc.getLength(), str, null);
              } else {
                   doc.insertString(doc.getLength()+1, str, null);
              } But that causes the 2nd String to begin on a whole new line, instead of continuing on the first line like it should. All the subsequent appends work good though.
    I've also tried:
    txtTest.setText(txtTest.getText()+str);That makes all the text line up correctly, but then all the previous highlighting is lost. The only String that's ever highlighted is the last one.
    I'm getting close to submitting a bug report on this, but I should see if anyone here can help first. Any ideas are much appreciated!

    It may work but it is nowhere near the correct
    solution.It seems to me the "correct" solution would be for Sun to fix the issue, because it seems they are secretly inserting a newline character into my Document. Here's a compilable program that shows what I mean:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Random;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.DefaultHighlighter;
    import javax.swing.text.DefaultStyledDocument;
    public class TestFrame extends JFrame {
         private JButton btnAppend = new JButton("Append");
         private DefaultStyledDocument doc = new DefaultStyledDocument();
         private JTextPane txtPane = new JTextPane(doc);
         private Random random = new Random();
         public TestFrame() {
              setSize(640, 480);
              setLocationRelativeTo(null);
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        dispose();
              getContentPane().add(new JScrollPane(txtPane), BorderLayout.CENTER);
              getContentPane().add(btnAppend, BorderLayout.SOUTH);
              btnAppend.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        doBtnAppend();
         private void doBtnAppend() {
              try {
                   String str = "00 A9 10 20 20 50 10 39 69 FF F9 00 20 11 99 33 00 6E ";
                   int start = doc.getLength();
                    * This line causes all highlights to have the same color,
                    * but the text correctly starts on the first line.
                   doc.insertString(doc.getLength(), str, null);
                    * This line causes all highlights to have the correct
                    * (different) colors, but the text incorrectly starts
                    * on the 2nd line.
    //               doc.insertString(doc.getLength()+1, str, null);
                    * This if/else solution causes the 2nd appended text to
                    * incorrectly start on the 2nd line, instead of being
                    * concatinated with the existing text on the first line.
                    * (a newline character is somehow inserted after the first
                    * line)
    //               if (doc.getLength() == 0) {
    //                    doc.insertString(doc.getLength(), str, null);
    //               } else {
    //                    doc.insertString(doc.getLength()+1, str, null);
                   int end = doc.getLength();
                   txtPane.getHighlighter().addHighlight(start, end, new DefaultHighlighter.DefaultHighlightPainter(randomColor()));
              } catch (BadLocationException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              EventQueue.invokeLater(new Runnable() {
                   public void run() {
                        new TestFrame().setVisible(true);
         private Color randomColor() { return new Color(intRand(0, 255), intRand(0, 255), intRand(0, 255)); }
         private int intRand(int low, int high) { return random.nextInt(high - low + 1) + low; }
    }Try each of the document insert lines in the doBtnAppend method and watch what it does. (comment out the other 2 of course)
    It wastes resources and is inefficient. A lot of work
    goes on behind the scenes to create and populate a
    Document.I tracked the start and end times in a thread loop to benchmark it, and most of the time the difference is 0 ms. When the document gets to about 7000 characters I start seeing delays on the order of 60 ms, but I'm stripping off text from the beginning to limit the max size to 10000. It might be worse on slower computers, but without a "correct" and working solution it's the best I can come up with. =)

  • Data View Web Part - List of Subsites and Document Libraries under Current Site - Must be able to Package as Site Template in SPDesigner

    Hi Guys,
    On the home page of each sub site I would like to be able to show a list of subsites and Document libraries that are under the current subsite.
    I started investigating a solution using Datasources with SOAP requests sent to the server but it is very difficult to understand how to surface it on the Data View WebPart.
    I have tried with the search results webpart but the problem is that it does not work well when packaged in a Site Template.
    Please advise.
    Thanks and Regards,
    Rhyan

    Ok,
    Here is the problem:
    When creating a mysite from powershell or script, apparently you can ONLY do this from a wfe (or a server running Microsoft SharePoint Foundation Web Application in services on server).
    You CANNOT create mysites from script on your appserver if it is not also a Web Application Server. I confirmed the same is true in my test farm. I guess I was always running most of these scripts on the webserver.
    I searched all over and cannot find this documented anywhere.
    Who do I contact to have Microsoft document this?
    It's Thursday morning, I've been working non stop since Saturday morning so you don't have to :)

  • "Downloads" and "Documents" Stacks in the Dock  10.6 Snow Leopard

    Is there a way to get the little blue folder icons that say "Downloads" and "Documents" to appear on the stacks in the dock instead of a thumbnail type icon of the first document or download in the stack? 10.6 Snow Leopard.  The Apple Web page describing "Stacks" as a new part of Snow Leopard shows them.

    Yes, right click (control click) on the icon and select Display as Folder.

  • Arching of files is gone from the downloads and documents folder

    The arching list of files is gone when rolling over the downloads and documents folder. I removed the downloads folder by accident yesterday from the dock. Once I found it, I replaced it back on the dock and now the arching of files is gone on both folders. I have them as lists by date. I have restarted my MacBook Pro several times, clicked on the dock and properties and nothing seems to work. Does anyone know how to get it back? Are there any settings that I am missing?. Thanks!

    Right click on the folder in the Dock (or hold down the Control key and click on it if you have a one-button mouse), and choose "Stack" under the "Display as" section, and "Fan" under the "View content as" section in the resultant contextual menu. You can also choose how they are sorted from this menu as well.
    Message was edited by: Dan Parnell

  • Need to convert pictures and documents to PDF

    need to convert pictures and documents to PDF

    Hi BodyWhys,
    Please do below if you are using Adobe Reader:
    1. Launch Reader
    2. Select "Tool" at right pane
    3. Sign in with your Adobe ID and password after clicking "Sign in" under "Tools"
    4. Select "Create PDF" tab
    5. Click "Select File" button
    6. Select your picture or document (please see more information on supported file at http://helpx.adobe.com/acrobat-com/kb/using-createpdf.html#main_Convert_a_file_to_PDF)
    7. Click "Convert" button
    8. Click "View PDF File in Reader" after converting the file
    Please do below if you are using online service
    1. Login to https://createpdf.acrobat.com/signin.html with your Adobe ID and password
    2. Select "Convert to PDF"
    3. Click "Select Files" button
    4. Click "Download" button in progress bar after convert is complete.
    Please let me know if you have more quetions.
    thank you.
    hisami

  • New to apple with my  ipad 4 wanted to transfer pics and documents from dell computer is that possible and how?

    Happy Holidays I am a new Apple user with the i-pad 4 being my first product.  I wanted to transfer pics and documents from my windows computers.  I logged into the network but do not know how to access it using the i-pad.  Is this possible?  What is the best way to save photos to the icloud.  I have pics in windows "pictures" in my yahoo email and in facebook.  I am also a frequent user of MS word and excel.  What apple product would you recommend that I use so taht I can access and modify my documents?  Thanks!  Rosebud

    See this migrate iTunes library post.
    tt2

  • Is the macbook compatible with PC's programs and documents and etc?

    I am switching from a PC to a macbook very soon, and my mom is worried that I will have this macbook and if I'm in a project or something with someone who has a PC, and i need something to be switched from my computer to theirs, or vice versa, that it won't work.

    yeah MS Office for mac is compatible with all word, powerpoint and excel files. As for programs no they're not, but Im sure you could find the same program or a look a like for the mac. If you could be more specific with your "programs" and "documents" that would be awesome.

  • Stock reservation report For customer wise and Document wise

    Dear sd experts ...
    In my company  we have kept some reserved stock to some customers By using MB1B-412E M.type now Requirement is I want to see how much stock kept in reservation for Customers and Document wise also
    I Have checked in CO09 But not possible and MCTA also
    plz guide me how to find

    did you try MMBE ?
    also check MB5B, MD04, MB5T

  • Difference between local amount and document amount in the same currency

    Dear All,
    Why different between local amount and document amount with the same currency in some FI document line items? Both currency is 'TWD' and update currecy(BSEG-PSWSL) is 'USD'.
    What is the purpose of update currency(BSEG-PSWSL) and update amount(BSEG-PSWBT) ?
    Does update curreny cause the difference mentioned above?
    Thanks all in advance.
    Best regards,
    SAP user

    Dear Sir,
    Thanks for your kindly response!
    These fields of the FI document header are following:
    Local currency 1(BKPF-HWAER) : TWD
    Local currency 2(BKPF-HWAE2) : null
    Local currency 3(BKPF-HWAE3) : null
    Document currency (BKPF-WAERS) : TWD
    Transcation currency means which field ?
    Transaction code (BKPF-TCODE) : FB1S
    The line items as following :
    Itm PK Account    Account  short text   Amount
    1   40   21302500  A/E-Maintenance     1,119,350
    2   50   21302500  A/E-Maintenance     1,119,350-
    Amount in document currency is 1,119,350(TWD) but amount in local currency is 1,087,998(TWD).
    The line item's additional data :
    Amount for Updating in General Ledger : 33,894.02(USD)
    Thanks a lot !!
    Best regards,
    SAP user

  • In mail, my attachments, both photos and documents appear in the body of the message.  How can I get my attachments to appear as a separate attachment and not as part of the message.  Thanks for your help, Karen.

    In mail, my attachments, both photos and documents, appear in the body of the message.  How can I get my attachments to appear as a separate attachment and not as part of the main message????  Thanks for your help, Karen.

    softwater wrote:
    ...and costs $14.99
    Yep! And if you absolutely need (or think you need) that functionality, it is worth every penny.
    As Don already pointed out, exactly what the recipient sees will depend on how they've set up their machine and what unnecessary 3rd party apps they might've installed to display attachments the way they want.
    In theory, that is true. In practice, Attachment Tamer will cause more of your messages to show up as plain-jane icons on the other end. The problem is, after all, people running Outlook 2003 and 2007. These people likely aren't doing many system modifications.
    If I were you, I'd use the free solutions provided above, save my money and let my recipients decide how they will handle their mail.
    I completely agree.

  • Invoice number and document number not printed in payment advice

    Hello Gurus,
           I am executing reprint check through transaction fch7, In that Invoice number and document number not printed in payment advice. I have created zscript for that and also assinged regup-belnr and regup-xblnr and used standard program RFFOUS_C.
    other fields from regup table are displayed but above two mentioned fields are not displayed.
          I even tried debugging standard RFFOUS_C prog, in that regup-belnr and regup-xblnr are coming but it is not printed on form.
    With regards,
    Vikram

    Hi,
    Debug you Zscript and check the invoice no and document no. Have assigned that script in FBZP..? check the which form is calling FCH7 in debugger mode..?
    Rgds
    Aeda.

  • Invoice Number and Document Number

    Are Invoice Number and Document Number in FI AR same?
    Dont they differ, I could find only one infoobject 0INV_DOC_NO relating to both.
    Is there any seperate infoobject which gives the document number in 0FIAR_C03.
    Please comment.
    Thanks.

    hi,
    are you looking for clearing doc number ?
    http://help.sap.com/saphelp_nw04s/helpdata/en/ee/cd143c5db89b00e10000000a114084/frameset.htm
    0CLR_DOC_NO - source field BSID-AUGBL
    hope this helps.

  • By backing up the iTunes Library via saving the iTunes folder on an external drive, is it also backing up all iPad and iPhone backups as well as App Data and Documents from your devices?

    If I backup my iTunes Library by saving the iTunes folder on an external hard drive using the instructions contained in the link below, will it also back up all my iPad and iPhone backups as well as App Data and Documents from my devices? In other words, will it also create backups for the backups? Thank you.
    Back up your iTunes library by copying it to an external drive
    Furthermore, when it is time to restore the iTunes folder I copied to my external drive to a new iTunes program on my new computer, how will it merge the information once I plug in my iPad or iPhone to that new laptop to sync? If I did the iTunes library backup a couple months ago and I've added documents/music/pictures on my devices since then, what will happen when I try to sync it with the new laptop now working off of the iTunes library backup from a couple months ago since the information is no longer the same? Which information will dominate and thus be kept? Will it delete the new information/data/pictures/documents/music off of the devices since it is not on the iTunes program when it syncs?
    Sorry for so many questions, but they are all related to backing up and restoring iTunes. I am not very tech savvy if you cannot tell

    It would be a good idea to look into a bigger hard drive. They are not that expensive any more and can save a lot of headach. This is even more important if you are buying music from the iTunes music store. If you lost those files they are gone.
    The point of having it on your PC and iPod is to have a backup. If the iPod fails, or you need to go back to the DVDs and find they are scratched, or just can not be read you have lost days of work converting and organizing all of those songs.
    Or the iPod could hard drive could fail and then you will have to try to bring all of those files back from DVDs. You end up with a mess since some songs will probably be on multiple DVDs, have different names ect. Trying to reorganize it all can be a pain.

Maybe you are looking for