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

Cursor loops infinitely in multiline JTextPane

    XMLWordPrintable

    Details

      Backports

        Description

        Name: jbT81659 Date: 03/24/2000

        Inserting multiline text in JTextPane causes the cursor to loop infintely.

        To reproduce bug:
        1- Compile and run attached example.
        2- Though all JTextPanes in example are initialized with text, insert more text until you have
        more than one line of bidi text.
        3- Go to Home position and begin scrolling by pressing the right or left arrow key on the
        keyboard so the cursor is moving constantly toward the END.
        4- Note that after passing the first line or couple of lines, the cursor
        goes back to beginning of line and starts scrolling over again.
        5- Try the same procedure for all JTextPanes in example.
        6- Note that all of the JTextPanes share this problem.
        7- Insert LTR text only. Note that this problem is there.
        8- Insert RTL text only. Note that this problem is there.

        ------Code------

        /* Copyright (c) Sun Microsystems 1999

        $Header: /home/sun/src/JDK1.2/jTextPane.java,v 1.16 1999/11/28 11:34:25 isam Exp $

        */

        import java.awt.*;
        import java.awt.font.*;
        import java.awt.event.*;
        import javax.swing.*;
        import javax.swing.border.*;
        import javax.swing.text.*;

        public class jTextPane extends JApplet
        {
          public void init()
          {
            jTextPane1 jpane = new jTextPane1();
            getContentPane().add(jpane);
          }

          public static void main(String[] args)
          {
            JFrame frame = new JFrame("\u0645\u062b\u0627\u0644");
            frame.setContentPane(new jTextPane1());
            frame.pack();
            frame.setVisible(true);
                frame.addWindowListener( new WindowAdapter()
                {
                     public void windowClosing( WindowEvent e)
                     {
                         System.exit(0);
                     }
                });

          }
        }
        class jTextPane1 extends JPanel
        {
          public jTextPane1()
          {
            JLabel l;
            JPanel p;
            JTextField field;
            JTextArea area;
            JTextPane pane;
            JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));

            p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
            l = new JLabel("JTP1 implicit, left");
            pane = new JTextPane();
            pane.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 9));
            l.setVerticalAlignment(SwingConstants.BOTTOM);
            l.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 9));
            pane.setPreferredSize(new Dimension(320, 320));
            pane.setText("\u062a\u0641\u0627\u062d\u0020\u0623\u062d\u0645\u0631\u0020\u05d9\u05d5\u05dd\u0020\u05e0\u05e2\u05d9\u05dd");
            p.add(l);
            p.add(pane);
            p.setPreferredSize(new Dimension(450,450));
            panel.add(p);

            p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
            l = new JLabel("JTP2 explicit RTL, left");
            pane = new JTextPane();
            pane.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 9));
            l.setVerticalAlignment(SwingConstants.BOTTOM);
            l.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 9));
            pane.getDocument().putProperty(TextAttribute.RUN_DIRECTION,TextAttribute.RUN_DIRECTION_RTL);
            pane.setPreferredSize(new Dimension(320, 320));
            pane.setText("\u0053\u0074\u0061\u0072\u0074\u0020\u062a\u0641\u0627\u062d\u0020\u0623\u062d\u0645\u0631\u0020\u05d9\u05d5\u05dd\u0020\u05e0\u05e2\u05d9\u05dd");
            p.add(l);
            p.add(pane);
            p.setPreferredSize(new Dimension(500,500));
            panel.add(p);

            p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
            l = new JLabel("JTP3 explicit RTL, right");
            l.setVerticalAlignment(SwingConstants.BOTTOM);
            l.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 9));
            pane = new JTextPane();
            pane.getDocument().putProperty(TextAttribute.RUN_DIRECTION,TextAttribute.RUN_DIRECTION_RTL);
            MutableAttributeSet rightStyle;
            rightStyle = new SimpleAttributeSet();
            StyleConstants.setAlignment(rightStyle,StyleConstants.ALIGN_RIGHT);
            StyledDocument doc = pane.getStyledDocument();
            SimpleAttributeSet a = new SimpleAttributeSet();
            //pane.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 9));
            pane.setText("\u0053\u0074\u0061\u0072\u0074\u0020\u062a\u0641\u0627\u062d\u0020\u0623\u062d\u0645\u0631\u0020\u05d9\u05d5\u05dd\u0020\u05e0\u05e2\u05d9\u05dd");
            pane.setParagraphAttributes(rightStyle,true);
            p.setPreferredSize(new Dimension(500,500));
            p.add(l);
            p.add(pane);
            pane.setPreferredSize(new Dimension(320, 320));
            panel.add(p);

            p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
            l = new JLabel("JTP4 explicit LTR, left");
            l.setVerticalAlignment(SwingConstants.BOTTOM);
            l.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 9));
            pane = new JTextPane();
            pane.setFont(new Font("Lucida Sans Regular", Font.PLAIN, 9));
            pane.getDocument().putProperty(TextAttribute.RUN_DIRECTION,TextAttribute.RUN_DIRECTION_LTR);
            pane.setPreferredSize(new Dimension(320, 320));
            pane.setText("\u062a\u0641\u0627\u062d\u0020\u0623\u062d\u0645\u0631\u0020\u05d9\u05d5\u05dd\u0020\u05e0\u05e2\u05d9\u05dd");
            p.add(l);
            p.add(pane);
            p.setPreferredSize(new Dimension(500,500));
            panel.add(p);
            
            panel.setPreferredSize(new Dimension(500,2000));

            JScrollPane scroll = new JScrollPane(panel);
            scroll.setPreferredSize(new Dimension(650,450));

            add(scroll);
          }
        }


        WorkAround:
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                rupashka Pavel Porvatov (Inactive)
                Reporter:
                jbenavrasunw Jonathan Benavraham (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: