Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Long last line in wrappable textarea hangs GUI (bug in java?)

843806Sep 17 2007 — edited Sep 18 2007
If I have a JTextarea or JEditorPane with a very long last line the GUI hangs.
I think it is a bug in java. I am really searching fo a workaround.
You can test it with the following program.
Just start the program and delete the last linebreaks (blank lines) one by one.
The gui will hang.

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class TextEdit extends JFrame
{

public static void main(String[] args)
{
TextEdit editor = new TextEdit();
editor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
editor.setVisible(true);
}

// Create an editor.
public TextEdit()
{
super("Swing Editor");
JTextArea area = new JTextArea();

int length = 1024 * 1024;

StringBuffer sb = new StringBuffer(length);
for (int i = 0; i < length; i++)
{
sb.append("A");
}
sb.append("\n");//append one line break
sb.append("\n");//append secondline break

area.setText(sb.toString());

area.setLineWrap(true);
Container content = getContentPane();
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(area);
content.add(scrollPane, BorderLayout.CENTER);
setSize(320, 240);
}

}

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 16 2007
Added on Sep 17 2007
3 comments
675 views