在Java中隐藏透明JScrollPane的边框

在Java中隐藏透明JScrollPane的边框,java,swing,border,jscrollpane,Java,Swing,Border,Jscrollpane,我已经实现了JScrollpane,并将不透明设置为false。现在的问题是我无法隐藏它的边界 代码: 图片: 我想隐藏箭头显示的边框 我试过两种方法: Border border = BorderFactory.createEmptyBorder( 0, 0, 0, 0 ); chapterScrollPane.setViewportBorder( border ); chapterScrollPane.setBorder(border); chapterContainerPanel.set

我已经实现了JScrollpane,并将不透明设置为false。现在的问题是我无法隐藏它的边界

代码:

图片:

我想隐藏箭头显示的边框

我试过两种方法:

Border border = BorderFactory.createEmptyBorder( 0, 0, 0, 0 );
chapterScrollPane.setViewportBorder( border );
chapterScrollPane.setBorder(border);
chapterContainerPanel.setBorder(null);

但两者都不起作用。

简短回答 使用borderFactory创建空边框

chapterScrollPane.setBorder(createEmptyBorder());

请尝试这行代码,希望它能解决您的问题

chapterScrollPane.setBorder(BorderFactory.createEmptyBorder());

我也有同样的问题,这对我来说很有效:

chapterScrollPane.setBorder(BorderFactory.createEmptyBorder());
chapterScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
执行此操作时,边框将不再显示,但滚动条内面板的内容可能位于滚动条下,因此您需要调整视口中面板的边框,在本例中为chapterContainerPanel。您还可以使用空边框来解决此问题,如下所示:

chapterContainerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 12);

你试过设置空边框吗?是的,我试过空边框,但不起作用。你设置了什么?您有3个主要组件。您使用的是pack()方法吗?如果没有,请尝试添加它。顺便说一句,您不必对每个组件调用setOpaque(false)方法,因为默认情况下它是false。您还有一个
chapterPanel
,您没有尝试将空边框设置为ChapterScrollPane。setViewportBorder(border)会将边框设置为chapterPanel@Dipali瓦萨尼你评论中的每一句话都是空洞的,在这种情况下,您将发布一个SSCCE/MCVE/MCTRE-short、runnable、compileable
chapterScrollPane.setBorder(BorderFactory.createEmptyBorder());
chapterScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
chapterContainerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 12);