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

Graphics.drawChars(...) incorrectly draws long lines of chars.

XMLWordPrintable

    • generic, sparc
    • solaris_2.6



      Name: dsC76952 Date: 05/20/99




      A panel which draws a long line of chars is put into ScrollPane.
      Notice that characters overlap each other. Nothing can be read.

      This is critical to show html sources with long lines in HotJava
      Browser (bug 4225539)

      The bug exist in jdk 1.1.6, 1.1.7, 1.1.8 (solaris, x86)


      ----------- file DrawCharsTest.java ------------------------

      import java.awt.*;

      public class DrawCharsTest {

          final private static String pattern = "test";
          // use this number to regulate char array size
          final private static int iterNum = 555;
          
          public static void main(String argv[]) {
              
              char data[];
              
      // create a long char array.

              StringBuffer sb = new StringBuffer(pattern.length() * iterNum);
              for (int i = 0; i < iterNum; i++) {
                  sb.append(pattern);
              }
              data = sb.toString().toCharArray();
              System.out.println("data length: " + data.length);

      Frame frame = new Frame();

      ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
      sp.setSize(500, 200);

      Panel p = new MyPanel(data);
      sp.add(p);

      frame.add(sp);

      frame.setLocation(100, 250);
      frame.pack();

              System.out.println(" panel size: " + p.getSize());
              System.out.println("scroll pane size: " + sp.getSize());

      frame.show();
          }
      }

      class MyPanel extends Panel {
          
          private char data[];

          MyPanel(char []data) {
              this.data = data;
          }

          public Dimension getPreferredSize() {
              return getMinimumSize();
          }

          public Dimension getMinimumSize() {
              return new Dimension(20000, 200);
          }

          public void paint(Graphics g) {

              FontMetrics fm = g.getFontMetrics(getFont());
              int dataWidth = fm.stringWidth(new String(data));
              System.out.println("data width: " + dataWidth);
              
              g.drawChars(data, 0, data.length, 0, 20);
          }
      }

      ----------- end file DrawCharsTest.java ------------------------


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

            ehawkessunw Eric Hawkes (Inactive)
            sdvsunw Sdv Sdv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: