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

Component JTextArea does not work with cursor position correctly.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.2
    • client-libs
    • x86
    • linux



      Name: kaC94536 Date: 01/17/2000



      Component JTextArea sometimes does not draw cursor position correctly.
      Frame window of following test contains a split pane, witch includes
      JTextArea component and buttons panel.
      By clicking on buttons "Next" and "Prev" you can change fonts of top text area.
      Often you can see that current cursor position does not correspond position of symbol being printed.

      Note that the TextArea component works correctly.

      --------------------test.java---------------------------------------------

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class test extends JFrame {

        static Font[] systemFontArray;
        protected int currentFontCount;
        protected JTextArea textArea;
              
        static {
          systemFontArray=GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
         }

        public test() {
          super("JTextArea test");
          currentFontCount = 0;

          textArea = new JTextArea();
          setAreaFont(currentFontCount);
          JPanel buttonPanel = new ButtonDemo(this);
          JSplitPane splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT, textArea, buttonPanel );
          splitPane.setDividerLocation(200);
          splitPane.setPreferredSize(new Dimension(500, 300));

          getContentPane().add(splitPane, BorderLayout.CENTER);
         }

        public void nextFont() {
          if (currentFontCount < systemFontArray.length-1) {
             currentFontCount++;
             setAreaFont(currentFontCount);
           }
         }

        public void prevFont () {
          if (currentFontCount > 0) {
             currentFontCount--;
             setAreaFont(currentFontCount);
           }
         }

        public void setAreaFont(int i) {
            textArea.setFont(new Font(systemFontArray[i].getFontName(), 0, 12));
            setTitle(systemFontArray[i].getFontName());
         }

        public static void main(String[] args) {
          JFrame frame = new test();
          frame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent e) {
              System.exit(0);
             }
           });
          frame.pack();
          frame.setVisible(true);
         }
      }

      class ButtonDemo extends JPanel implements ActionListener {
          JButton b1, b2;
          test t;

          public ButtonDemo(test areatest) {
              t = areatest;

              b1 = new JButton("next");
              b1.setVerticalTextPosition(AbstractButton.CENTER);
              b1.setHorizontalTextPosition(AbstractButton.LEFT);
              b1.setActionCommand("next");
              b1.addActionListener(this);
              b1.setToolTipText("Get next system font");
              add(b1);

              b2 = new JButton("prev");
              b2.setVerticalTextPosition(AbstractButton.BOTTOM);
              b2.setHorizontalTextPosition(AbstractButton.CENTER);
              b2.setActionCommand("prev");
              b2.addActionListener(this);
              b2.setToolTipText("Get previous system font");
              add(b2);
          }

          public void actionPerformed(ActionEvent e) {
              if (e.getActionCommand().equals("next")) {
                  t.nextFont();
               }
              else {
                  t.prevFont();
               }
          }
      }

      ======================================================================

      ======================================================================

      Name: kaC94536 Date: 02/02/2000



      When some font is set and some symbols are printed in JTextArea component (for example,
      "m", "l" and many others), the size of cursor displacement does not correspond size of the
      symbol.
      This happens the following fonts are used:

      Bitstream Charter Bitstream Charter Bold Bitstream Charter Bold Italic
      Bitstream Charter Italic monocpaced Courier 10 Pitch
      Courier 10 Pitch Bold Courier 10 Pitch Bold Italic Courier 10 Pitch Italic
      Courier Bold Italic Courier Italic Lucuda Bright Demibold
      Lucuda Bright Demibold Italic Lucuda Bright Italic Lucida Bright Regular
      Lucida Sans Demibold Lucida Sans Demibold Oblique Lucida Sans Oblique
      Lucida Sans Regular Lucida Sans Typewriter Bold Lucida Sans Typewriter Bold Oblique
      Lucida Sans Typewriter Oblique Lucida Sans Typewriter Regular Utopia Bold
      Utopia Bold Italic Utopia Italic Utopia Regular
      dialog dialog.bold dialog.bolditalic
      dialog.italic dialoginput dialoginput.bold
      dialoginput.bolditalic dialoginput.italic monospaced
      monospaced.bold monospaced.bolditalic monospaced.italic
      sansserif sansserif.bold sansserif.bolditalic
      sansserif.italic serif serif.bold
      serif.bolditalic
      serif.italic

      ======================================================================

            mbronsonsunw Mike Bronson (Inactive)
            kanisimosunw Konstantin Anisimov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: