This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

repaint problems DDRAW.DLL  RSS feed

 
simcel jones
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, thanks for reading this
I am having problems when I call repaint.
I have a JFrame with a JPanel with drawLine()
When I call repaint the repaint is not clean.
The old image remains and a new image is redrawn in the wrong place, also the JButton used to call repaint is drawn
After searching the forum I have tried amending DDRAW.DLL and using java -Dsun.java2d.noddraw but am still having problems
please can you help
many thanks
simon
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posting the code will help.
 
simcel jones
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Cindy
thanks for replying
I did not post the code because it is fairly lenghty and convoluted.
I have made progress though

I have a JFrame with a JPanel 'A' which holds a JPanel 'B'
I am drawing on 'B'
When I called B.repaint() the drawing is messy
However when I call repaint on 'A' the drawing on 'B' is perfect
so it seems that I need to call repaint on the owner of the Jpanel I am painting
Is this correct and if so can you explain why?
Many thanks for your time
simon
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is all explained very nicely here: http://java.sun.com/docs/books/tutorial/uiswing/overview/draw.html
 
simcel jones
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your time cindy
the article is excellent
simon
 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use paintComponent(Graphics) instead of paint(Graphics) if this is what you are using. Also, you should put a call to super.paintComponent(Graphics) at the very beginning of paintComponent(). For example:
public void paintComponent(Graphics gfx) {
super.paintComponent(gfx);
// rest of drawing code...
}
Hope that helps.
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel,
Can you pls. elaborate on using paintComponent() instead of paint()?
I mean how they are different?
regards
deeksha
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!