Reputation: 2536
I have implemented JScrollpane and I had set opaque false. Now the problem is I am not able to hide it's border.
Code:
JPanel chapterContainerPanel = new JPanel();
JScrollPane chapterScrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
chapterContainerPanel.setOpaque(false);
chapterScrollPane.setViewportView(chapterPanel);
JLabel blankLabelChapter = new JLabel();
blankLabelChapter.setOpaque(false);
blankLabelChapter.setPreferredSize(new java.awt.Dimension(150, 50));
blankLabelChapter.setRequestFocusEnabled(false);
chapterContainerPanel.add(blankLabelChapter,BorderLayout.WEST);
chapterContainerPanel.add(chapterScrollPane,BorderLayout.CENTER);
chapterScrollPane.setOpaque(false);
chapterScrollPane.getViewport().setOpaque(false);
Image:
I want to hide the border which is shown by arrow.
I have tried two ways:
Border border = BorderFactory.createEmptyBorder( 0, 0, 0, 0 );
chapterScrollPane.setViewportBorder( border );
chapterScrollPane.setBorder(border);
chapterContainerPanel.setBorder(null);
and
chapterScrollPane.setBorder(null);
chapterScrollPane.setViewportBorder(null);
but both are not working.
Upvotes: 1
Views: 1438
Reputation: 1568
I was having the same problem, and this worked for me:
chapterScrollPane.setBorder(BorderFactory.createEmptyBorder());
chapterScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
Doing this that border will no longer appear, but the content of the panel inside the Scroll might go under the ScrollBar, so you need to adjust the border of the panel that is on the ViewPort, chapterContainerPanel in your case. You can also use an empty border to solve this, like that:
chapterContainerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 12);
Upvotes: 3
Reputation: 4047
Please try this line of code, hope it will solve your issue,
chapterScrollPane.setBorder(BorderFactory.createEmptyBorder());
Upvotes: 2
Reputation: 906
Short answer Use borderFactory to create empty border
chapterScrollPane.setBorder(createEmptyBorder());
Upvotes: 0