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

JTextPane not working with a large file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs



      Name: rk38400 Date: 04/16/98


      JTextPane is not working with a large file inside
      the pane. If you run this program and feed it a
      large file, like Character.java from the jdk sources,
      on the command line:
        java FilePane Character.java
      and then click inside the text pane, it does
      bad things:
        - the background color is wrong
        - the text is garbled visually

      Note: this is a bitter disappointment to me
      because I've been struggling for a long time with
      the AWT TextArea and its limit of 32K on the size
      of the contents of a TextArea. I thought this
      would be fixed with Swing. Looks like it isn't,
      yet. Here's the program source:

      import com.sun.java.swing.*;
      import com.sun.java.swing.text.*;
      import java.awt.*;
      import java.io.*;

      class FilePane extends JFrame {
        
        public static void main (String [] argv) {
          // SystemLAF.setSystemLAF();
          String fileName = (argv.length > 0) ? argv[0] : "FilePane.java";
          new FilePane(fileName);
        }

        FilePane (String fileName) {
          byte [] contents = null;
          setName(fileName);
          setSize(600, 500);
          try {
            FileInputStream FIS = new FileInputStream(fileName);
            BufferedInputStream BS = new BufferedInputStream(FIS);
            int siz = BS.available();
            contents = new byte[siz];
            int nread = BS.read(contents, 0, siz);
            System.out.println("nread=" + nread);
          } catch (Exception e) {
            e.printStackTrace();
            return;
          }

          JTextPane textPane = new JTextPane();
          textPane.setText(new String(contents));
          JScrollPane scroller = new JScrollPane(textPane,
      ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
          JPanel panel = new JPanel();
          panel.setLayout(new BorderLayout());
          panel.add(scroller, BorderLayout.CENTER);
          getContentPane().add(panel);
          setVisible(true);
        }
      }
      (Review ID: 28307)
      ======================================================================

            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: