Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JScrollPane not repaint Canvas when scrolling?

I trying to make a game where I add a Canvas to a JScrollPane but the canvas is larger than the visible area of the JScrollPane. So when I scroll the JScrollPane to see the rest I only see the blank area even though my Canvas is continuously redrawn. Anybody can help me??

like image 825
Phat RedDevil Avatar asked Mar 18 '26 21:03

Phat RedDevil


2 Answers

It is common JScrollPane problem. To fix this with minimum fuss, call the following methods on your JScrollPane:

scrollpane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
like image 94
freecoder Avatar answered Mar 21 '26 10:03

freecoder


Swing components do not work with heavyweight AWT components like Canvas. Use a JComponent or a JPanel instead of a Canvas

like image 39
user1288739 Avatar answered Mar 21 '26 10:03

user1288739



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!