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

JTextField cannot setText with Tab

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.0
    • 1.1.5
    • client-libs
    • swing1.1
    • x86
    • windows_nt



      Name: rk38400 Date: 04/14/98


      Run the enclosed program against Swing 1.0
      and get exception below:
      java.lang.ArithmeticException: / by zero
      at com.sun.java.swing.text.PlainView.nextTabStop(PlainView.java:433)
      at com.sun.java.swing.text.Utilities.getTabbedTextWidth(Utilities.java:104)
      at com.sun.java.swing.text.FieldView.getPreferredSpan(FieldView.java:173)
      at com.sun.java.swing.text.FieldView.updateVisibilityModel(FieldView.java:130)
      at com.sun.java.swing.text.FieldView.insertUpdate(FieldView.java:238)
      at com.sun.java.swing.text.DefaultTextUI$RootView.insertUpdate(DefaultTextUI.java:834)
      at com.sun.java.swing.text.DefaultTextUI$UpdateHandler.insertUpdate(DefaultTextUI.java:1050)
      at com.sun.java.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:137)
      at com.sun.java.swing.text.AbstractDocument.insertString(AbstractDocument.java:415)
      at com.sun.java.swing.text.JTextComponent.setText(JTextComponent.java:1089)
      at TestSetText.<init>(TestSetText.java:19)
      at TestSetText.main(TestSetText.java:24)

      Test program: (NOTE: The first line of the source code contains tabs)

      // Tabs here Tab1 Tab2 ...
      import java.awt.*;
      import java.io.*;
      import com.sun.java.swing.*;
      public class TestSetText extends JPanel {
          private JTextField text;
          TestSetText() {
      File file = new File("TestSetText.java");
      String initText = "";
      try {
      int length = (int)file.length(); // throws SecurityException for unreadable
      FileInputStream fs = new FileInputStream(file); // throws FileNotFoundException
      byte [] content = new byte[length];
      int bytesRead = fs.read(content); // throws IOException
      initText = new String(content, 0, bytesRead);
      } catch ( Exception ex ) {
      }
      text = new JTextField(30);
      text.setText(initText.substring(0,30));
      add(text);
          }
          public static void main(String args[]) {
      Frame f = new Frame();
      f.add(new TestSetText());
      f.pack();
      f.show();
          }
      }
      (Review ID: 27175)
      ======================================================================

            tprinzing Tim Prinzing (Inactive)
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: