RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

RSyntaxTextArea acting weird on non-opaque window

Open mgarin opened this issue 11 years ago • 0 comments

This is a really-really-really weird case I have encountered while playing around with RSyntaxTextArea placed inside custom-decorated (non-opaque) windows.

With some specific settings including line wrap and custom lines/rows amount I was able to reproduce this on a "clear" example, here it is:

public class SqlEditorTest extends RSyntaxTextArea
{
    public SqlEditorTest ( final String text )
    {
        super ();

        setColumns ( 60 );
        setRows ( 10 );
        setLineWrap ( true );
        setWrapStyleWord ( true );
        setSyntaxEditingStyle ( SyntaxConstants.SYNTAX_STYLE_SQL );

        setText ( text );
    }

    public RTextScrollPane createScroll ()
    {
        final RTextScrollPane editorScroll = new RTextScrollPane ( this );
        editorScroll.setVerticalScrollBarPolicy ( WebScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
        return editorScroll;
    }

    public static void main ( final String[] args )
    {
        final JFrame frame = new JFrame ();

        final String sql = "SELECT (SELECT d.balance FROM acc_account a, iss_card_number b, iss_card c, acc_balance d WHERE " +
                "a.customer_id = c.customer_id and c.id = b.card_id and d.account_id = a.id and d.balance_type = 'BLTP0001' " +
                "and b.CARD_NUMBER = ?)-(SELECT d.balance FROM acc_account a, iss_card_number b, iss_card c, " +
                "acc_balance d WHERE a.customer_id = c.customer_id and c.id = b.card_id and d.account_id = a.id " +
                "and d.balance_type = 'BLTP0002' and b.CARD_NUMBER = ?) as TRANSACTION_AMOUNT FROM DUAL";

        final SqlEditorTest sqlEditor = new SqlEditorTest ( sql );
        sqlEditor.setCaretPosition ( 0 );
        frame.getContentPane ().add ( sqlEditor.createScroll () );

        frame.setUndecorated ( true );
        AWTUtilities.setWindowOpaque ( frame,false );

        frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
        frame.pack ();
        frame.setLocationRelativeTo ( null );
        frame.setVisible ( true );
    }
}

In this example rendering is failing hard until you change anything in the text: image Type something or just add a new line (whatever works) and it is fixed: image Bug doesn't come back even if get the text to initial state (by either editing or using undo): image

Highlight (syntax editing style) doesn't really matter there - I was just copying it from my SQL-related code. Option setWrapStyleWord also doesn't matter - bug appears with simple line wrap as well.

So the key steps to reproduce this issue are:

  1. Use setLineWrap ( true );
  2. Set long text that uses single line but doesn't fit in one line in editor
  3. Setup area so that text fits without scroll (setup area rows/cols)
  4. Make window non-opaque using either AWTUtilities or transparent background on JDK7+

About 3rd - bug won't appear if you use for example setRows ( 4 ); instead of setRows ( 10 );. But it will appear if you only reduce the columns to setColumns ( 30 );.

As you can see - this bug is something really shady. I guess it might be something about area initialization since it fixes itself after any text change. It seems to happen on any JDK version - I have tried a it under various 6/7/8 versions - all the same.

mgarin avatar Aug 07 '14 12:08 mgarin