File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollPane and paint" Watch "JScrollPane and paint" New topic
Author

JScrollPane and paint

Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Hi,
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.
Best,
Damu
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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
Bartender

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.


-Nate
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
 
Similar Threads
JTable rows are getting visible in the middile of the JFrame only
scrollbar and image
how to change JScrollPane size?
JScrollPane and FlowLayout
JFrame