Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6524228

GapContent.insertString does not show all the strings

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_01-ea"
      Java(TM) SE Runtime Environment (build 1.6.0_01-ea-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_01-ea-b03, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux jupiter 2.6.19-1.2895.fc6 #1 SMP Wed Jan 10 18:50:56 EST 2007 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      One should be able to add String to an instance of GapContent prior to creating an instance of DefaultStyledDocument and have that String display correctly. However, only the first character is displayed. While if a String is added afterwards, that gets displayed correctly. See the following code snippet (full example program follows later):

      gapContent.insertString(0, "ABC"); // only the 'A' gets displayed
      DefaultStyledDocument document = new DefaultStyledDocument(gapContent, styleContext);
      gapContent.insertString(0, "XYZ"); // "XYZ" gets displayed

        Program displays "XYZA".


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see above

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      String ABC should be displayed in full, example program should display "XYZABC".
      ACTUAL -
      Example program displays "XYZA".

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import javax.swing.JFrame;
      import javax.swing.JTextPane;
      import javax.swing.SwingUtilities;
      import javax.swing.WindowConstants;
      import javax.swing.text.BadLocationException;
      import javax.swing.text.DefaultStyledDocument;
      import javax.swing.text.GapContent;
      import javax.swing.text.StyleContext;

      public class AppBug
      {
          public static void main(String[] args)
          {
              SwingUtilities.invokeLater(new Runnable()
              {
                  public void run()
                  {
                      try
                      {
                          new AppBug().go();
                      }
                      catch (final Exception e)
                      {
                          e.printStackTrace();
                      }
                  }
              });
          }

          private void go()
              throws BadLocationException
          {
              JFrame jFrame = new JFrame("AppBug");
              jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              GapContent gapContent = new GapContent();
              StyleContext styleContext = new StyleContext();

              gapContent.insertString(0, "ABC"); // only the 'A' gets displayed

              DefaultStyledDocument document =
                  new DefaultStyledDocument(gapContent, styleContext);

              gapContent.insertString(0, "XYZ"); // "XYZ" gets displayed

              JTextPane jTextPane = new JTextPane(document);
              jTextPane.setPreferredSize(new Dimension(250, 155));
              jFrame.add(jTextPane);
              jFrame.pack();
              jFrame.setVisible(true);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      never add content to and instance of GapContent prior to creating a DefaultStyledDocument.

            peterz Peter Zhelezniakov
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: