JScrollPane with transparent background and content

In my application, I show a popup dialog to show a large list of cards. I show them as images in many components JLabelin a subclass JPanel. Then I put this object in JScrollPaneto allow horizontal scrolling across the maps.

I want the unused space to be transparent with a dark background to show what is turned off behind it. I used setBackground(new Color(50, 50, 50, 200))to achieve the look that I want, but the content behind it does not redraw, so I get artifacts.

Here's what it looks like:

Artifacting when scrolling

How can i fix this? How can I get the content to redraw it while scrolling?

Thanks in advance.

+5
source share
2

.

JScrollPane JViewport, . , , - , .

, setOpaque(false) .

, .

, Swing "" ( , ).

, paintComponent (, )

+6

... . , , . .

    jScrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        @Override
        public void adjustmentValueChanged(final AdjustmentEvent e) {
            sevenWondersframe.repaint();
        }
    });
    jScrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        @Override
        public void adjustmentValueChanged(final AdjustmentEvent e) {
            sevenWondersframe.repaint();
        }
    });
+1

All Articles