4 Replies Latest reply on Apr 27, 2008 6:14 PM by 843806

    Line lengths in JTextPane or JTextArea

      Hi everybody,
      This is a conceptual question, no code involved. I've been looking over the forum, and there are quite a few posts about the maximum number of characters allowed in a JTextPane or JTextArea, but I haven't seen any posts that ask the question of how many characters are allowed in a single line before it wraps. The reason I'm curious about this is, I've noticed with a lot of text editors, like emacs or Notepad in Windows, the lines wrap after a few hundred or maybe a thousand characters, even if you have word wrap off. Does anyone know what the limit is for line wrapping in either JTextPanes or JTextAreas?

        • 1. Re: Line lengths in JTextPane or JTextArea
          If you have the time and patience, run this and find out... I'm up to 130000 and my processor fan's protesting ;-)
          import java.awt.event.ActionEvent;
          import javax.swing.AbstractAction;
          import javax.swing.JFrame;
          import javax.swing.JScrollPane;
          import javax.swing.JTextArea;
          import javax.swing.SwingUtilities;
          import javax.swing.SwingWorker;
          import javax.swing.Timer;
          public class TextAreaMaxLine {
             int max = 0;
             Timer timer;
             void makeUI() {
                final JTextArea textArea = new JTextArea();
                JScrollPane scrollPane = new JScrollPane(textArea);
                JFrame frame = new JFrame("TextAreaMaxLine");
                frame.setSize(500, 70);
                timer = new Timer(1, new AbstractAction() {
                   public void actionPerformed(ActionEvent e) {
                      new SwingWorker<String, Void>() {
                         protected String doInBackground() throws Exception {
                            if (max % 1000 == 0) {
                               System.out.println(max * 10);
                            return "1234567890";
                         protected void done() {
                            try {
                               if (textArea.getLineCount() > 1) {
                                  System.out.println(max * 10);
                            } catch (Exception ignore) {
             public static void main(String[] args) {
                SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                      new TextAreaMaxLine().makeUI();

          edit Hit 270000 before stopping the run... processor zone was up to 72 Celsius -- 4� above the alarm limit.

          Edited by: Darryl.Burke
          • 2. Re: Line lengths in JTextPane or JTextArea
            Wow, 270,000?! That's more than enough for what I need. I was just hoping the line would be bigger than 30,000. Thank you for your quick answer. I feel bad that I made you bake your processor.

            Thanks again,
            • 3. Re: Line lengths in JTextPane or JTextArea
              Next time tell me how much you need :-) If I'd known the requirement, I would have just concated a String of 30k characters and setText in one shot.

              • 4. Re: Line lengths in JTextPane or JTextArea
                Sorry! I had no idea JTextPanes and JTextAreas could hold nearly that much on one line.

                I hope your computer recovers from its processor souflee. :)

                Sorry again!