2

I'm trying to create a scrollable menu with item in them

I want to be able to draw a custom background to the scroll and have it be fixed when I scroll among the items

to do the draw of the background I use

@Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if(background != null){
            background.paintIcon(this,g);
        }
    }

my problem when I try to set the JScrollBar container opacity to false I get a white background

enter image description here

as you can I see I want the background to be the same "surface" as the other parts.

any idea what is causing this problem?

Jason

Jason Rogers
  • 19,194
  • 27
  • 79
  • 112

1 Answers1

4

A common problem. You don't actually 'see' the JScrollPane, but the Viewport of the JScrollPane. You need to do all your GUI actions on the JScrollPane.getViewport() (or something like that)

So to make a JScrollPane transparent you would use JScrollPane.getViewport().setOpaque(false)

Vincent Koeman
  • 751
  • 3
  • 9
  • and what should I do with that? getViewPort().setOpac(false); – Jason Rogers Jun 08 '11 at 15:25
  • thanks did the trick. I mist say what a stupid bug !!!(can you edit your answer just to make it more obvious for other people reading this in search of help^^_ – Jason Rogers Jun 08 '11 at 15:32
  • sure, done ;) It's not really a bug, as the JScrollPane is just a Viewport+1 or 2 Scrollbars. – Vincent Koeman Jun 08 '11 at 15:33
  • 1
    +1 Here's a related [example](http://stackoverflow.com/questions/3517722/java-transparent-jscrollpane/3518047#3518047) that paints both viewport and view in contrasting colors. – trashgod Jun 08 '11 at 20:45