• Post Reply Bookmark Topic Watch Topic
  • New Topic

repaint in ScrollPane does not work correctly  RSS feed

 
Raschin Ghanad
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a scollpane and a Panel in it.
Without the scollpane, I can resize my Panel as I want, it repaints always correctly.

I don't use any Layout manager, I ask how much size does my frame gives me to draw and then calculate all relative corrdinates from this numbers.

Why does it display wrong when scrolling in the scrollpane?
Is it possible to catch all the events, that my scollpane sends to my Panel?

Maybe that would be a way to see what really happens/what goes wrong...
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each time the JScrollPane must validate itself it looks for the size of its viewports child, your JPanel, which it uses to set its scrollbars. So your custom component must let the JScollPane know what size it is or wants to be shown with. One way to do this is to override the JComponent method getPreferredSize in your component and return the desired Dimension. The JScrollPane will ask for this during each validate episode.

Calling the JComponent method revalidate on an instance of MyPanel in your event code signals the JScrollPane to validate itself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!