RSyntaxTextArea
RSyntaxTextArea copied to clipboard
A long text in one line, setLineWrap(true) does not work
There is a paragraph in one line, but the textarea' s width is some limit, I try to setLineWrap(true) to make it wrap, but it does not work. The whole paragraph is still in one line and there is a long y-scroll bar.
How can make auto wrap work?
Can you provide a small example application that demonstrates this behavior?
I'm having the same problem. Here is an example to reproduce. Using RSyntaxTextArea 2.5.8: compile 'com.fifesoft:rsyntaxtextarea:2.5.8'
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import javax.swing.*;
public class WrapTest {
public static void main( String[] args ) throws Exception {
SwingUtilities.invokeAndWait(()->{
RSyntaxTextArea textArea = new RSyntaxTextArea("r-syntax with a long line that should wrap",3,10);
//JTextArea textArea = new JTextArea("j-text with a long line that should wrap",3,10);
textArea.setLineWrap(true);
JPanel panel = new JPanel();
panel.add(textArea);
JFrame frame = new JFrame("test line wrap");
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
});
}
}
This seems to be related to the layout of your content pane. This fixes it:
JPanel panel = new JPanel(new BorderLayout());
Alternatively, keep the default content pane (which I think has BorderLayout installed by default, IIRC):
frame.getContentPane().add(new JScrollPane(textArea));
Switching to BorderLayout does hide the problem. I would consider this a work around solution. I may not be able to use this solution in my production environment, but I'll try.
The code example I gave also has a JTextArea that is commented out. If you comment out the RSyntaxTextArea and uncomment the JTextArea then you'll see my code example works and the line is wrapped. I interpret this as RSyntaxTextArea deviating from the contract for setLineWrap since RSyntaxTextArea is subclassing JTextArea and has changed the behavior of JTextArea in a way that isn't adding a feature or functionality but is instead a side effect or bug.
How do you interpret this change in behavior from JTextArea's line wrap to RSyntaxTextArea? Was it intended? Is there something I'm missing?
You're right, we should work if JTextArea works. I'll reopen.