jQuery in Action, 3rd edition
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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: 24195

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 agree. Here's the link: http://aspose.com/file-tools
subject: JScrollPane and paint
It's not a secret anymore!