Search code examples
javaswingborderjscrollpane

JScrollPane adding one white pixel along bottom and right edges


I have a JFrame in which I have a JScrollPane which has a JPanel. I draw some images in my JPanel.

My problem is that I noticed that the JScrollPane is adding one white pixel along the bottom and right edges of my window.

enter image description here

If I comment out my JScrollPane entirely (and add a line to add the JPanel into the JFrame), the white pixel border is not there.

enter image description here

This is what my code looks like:

panel = new JPanel();
panel.setPreferredSize(new Dimension(160,128));
panel.setLayout(new FlowLayout(FlowLayout.CENTER, 0,0));


scrollPane = new JScrollPane(panel);
scrollPane.getViewport().setPreferredSize(new Dimension((160,128));
this.add(scrollPane);

scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

Q: How do I get rid of that white "border" ?


Solution

  • Try the next:

    scrollPane.setBorder(null);