Closed TangGuoNiuBi closed 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:
For comparison, default style would look like this:
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.
I'll be closing this issue, but feel free to reopen it in case your question wasn't fully answered.
Use the weblaf, JScrollPane.setOpaque(false) cannot take affect any more! I'm a Chinese,my English is poor!