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

The spec for swing.text.JTextComponent.setText() does not specify position

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.5.1



      Name: akC57697 Date: 08/19/98



       The spec for swing.text.JTextComponent does not specify caret position
       in the linked document when the text has been inserted.

       The doc:
       "
      public void setText(String t)
           * Sets the text of this TextComponent to the specified text. If the
           * text is null or empty, has the effect of simply deleting the old text.
           * <p>
           * This method is thread safe, ...
           
           * @param t the new text to be set
           * @see #getText
           * @beaninfo
           * description: the text of this component
           */
       
       "
      The example works differently under jdk1.2beta4 and jdk1.2fcsF:
      -------------------------------8-<--------------------------------
      import com.sun.java.swing.JTextPane;
      import com.sun.java.swing.text.*;

      class Test {
        public static void main(String[] argv) {


            SimpleAttributeSet ast = new SimpleAttributeSet();
            StyledDocument doc = new DefaultStyledDocument();


            JTextPane c = new JTextPane(doc);
             StubIcon sc = new StubIcon();

             c.setCharacterAttributes(ast,true);
             c.setText("The text");

             System.out.println("The pos 1:"+c.getCaretPosition());
             c.insertIcon(sc);
             System.out.println("The pos 2:"+c.getCaretPosition());
                   
             System.exit(0);
         }
      }

         class StubIcon extends Object implements com.sun.java.swing.Icon {
          public StubIcon() {
          }
          public void paintIcon(java.awt.Component c, java.awt.Graphics g,
                                int x, int y) {}
          public int getIconWidth() {return 0;}
          public int getIconHeight() {return 0;}
          
         }

      -------------------------------8-<--------------------------------
       Output in JDK-1.2beta4-K:
      The pos 1:8
      The pos 2:9

       Output in JDK-1.2fcs-F:
      The pos 1:0
      The pos 2:0
       
         
      ======================================================================

            sharonz Sharon Zakhour (Inactive)
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: