This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JScrollPane and paint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollPane and paint" Watch "JScrollPane and paint" New topic

JScrollPane and paint

Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
I am trying to paint something on a JPanel, I extends the Jpanel and overrided the paint() method in it, then put the MyJpanel into a JScrollPane.
But when I dragged the scroll bar, the drawing in JPanel is blured. That is no repainting, how to solve it? Thanks.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

Swing components are a bit different than AWT ones. Instead of overriding paint(), override paintComponent(Graphics) instead.

[Jess in Action][AskingGoodQuestions]
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Hi, thank you, I tried but no improve.
I tried paintChildren, it works ?
[ January 19, 2004: Message edited by: damu liu ]
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You shouldn't override paintChildren(), or you won't be able to see any components that are added to your panel. When you override paintComponent( Graphics g ) the first line should be -

Then do your custom painting.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
hi Nathan,
Thank you, I followed yuor suggestion, it works perfect!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: JScrollPane and paint
It's not a secret anymore!