RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

A long text in one line, setLineWrap(true) does not work

Open zachary-guo opened this issue 9 years ago • 5 comments

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?

zachary-guo avatar May 27 '16 13:05 zachary-guo

Can you provide a small example application that demonstrates this behavior?

bobbylight avatar Jun 03 '16 23:06 bobbylight

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);
        });
    }
}

jzwolak avatar Jun 30 '16 15:06 jzwolak

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));

bobbylight avatar Jul 03 '16 14:07 bobbylight

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?

jzwolak avatar Jul 04 '16 00:07 jzwolak

You're right, we should work if JTextArea works. I'll reopen.

bobbylight avatar Jul 06 '16 03:07 bobbylight