具有自定义背景的 JScrollPanel

发布于 2024-11-14 09:02:14 字数 482 浏览 2 评论 0原文

我正在尝试创建一个可滚动的菜单,其中包含项目

我希望能够为滚动绘制自定义背景,并在我在项目之间滚动

以绘制背景

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

时修复它当我使用我的问题时尝试将 JScrollBar 容器不透明度设置为 false 我得到白色背景

在此处输入图像描述

如您所见,我想要背景是相同的“表面”和其他部分一样。

知道是什么导致了这个问题吗?

贾森

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2024-11-21 09:02:14

一个常见问题。您实际上“看到”的不是 JScrollPane,而是 JScrollPane 的视口。您需要在 JScrollPane.getViewport() (或类似的东西)上执行所有 GUI 操作,

因此要使 JScrollPane 透明,您可以使用 JScrollPane.getViewport().setOpaque(false)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文