开发者

JScrollPanel with custom background

开发者 https://www.devze.com 2023-03-11 02:35 出处:网络
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

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

JScrollPanel with custom background

开发者_Python百科

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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号