mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.14k stars 235 forks source link

JScrollPane's Problem #659

Closed TangGuoNiuBi closed 3 years ago

TangGuoNiuBi commented 3 years ago

Use the weblaf, JScrollPane.setOpaque(false) cannot take affect any more! I'm a Chinese,my English is poor!

mgarin commented 3 years ago

If you want to make the inner content of JScrollPane to be transparent - you will need to apply a custom style to the JScrollPane. Changing opacity won't work because decoration background is not affected by it.

If you want to make JScrollPane fully transparent - I recommend using existing StyleId.scrollpaneTransparent style.

Here is a full example:

public class Example
{
    public static void main ( final String[] args )
    {
        SwingTest.run ( new Runnable ()
        {
            @Override
            public void run ()
            {
                final JLabel content = new JLabel ( "Sample" );

                final JScrollPane scrollPane = new JScrollPane ();
                scrollPane.setPreferredSize ( new Dimension ( 500, 500 ) );
                StyleId.scrollpaneTransparent.set ( scrollPane );

                TestFrame.show ( new BorderLayout (), scrollPane )
                        .setContentBackground ( new Color ( 255, 170, 132 ) );
            }
        } );
    }
}

Or alternative, using WebScrollPane component:

public class Example
{
    public static void main ( final String[] args )
    {
        SwingTest.run ( new Runnable ()
        {
            @Override
            public void run ()
            {
                final JLabel content = new JLabel ( "Sample" );

                final WebScrollPane scrollPane = new WebScrollPane ( StyleId.scrollpaneTransparent, content );
                scrollPane.setPreferredSize ( new Dimension ( 500, 500 ) );

                TestFrame.show ( new BorderLayout (), scrollPane )
                        .setContentBackground ( new Color ( 255, 170, 132 ) );
            }
        } );
    }
}

Result:

image

For comparison, default style would look like this:

image


Overall - I recommend reading Styling introduction wiki article. It should explain how styling works in WebLaF and how you can make your own custom styles for any component.

mgarin commented 3 years ago

I'll be closing this issue, but feel free to reopen it in case your question wasn't fully answered.