具有自定义背景的 JScrollPanel
我正在尝试创建一个可滚动的菜单,其中包含项目
我希望能够为滚动绘制自定义背景,并在我在项目之间滚动
以绘制背景
@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
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个常见问题。您实际上“看到”的不是 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)