File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resizing window erases content of Graphics2d

 
Fernando Piovani
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every time i resize the window, or open a new window in front of it, the content (drawed lines) are erased. How can i avoid that?

Also, can some explain why this happens in technical terms?

[ ]´s
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post some code, because we shall need more details to work on.

I shall move this thread to our GUIs forum, because it sounds a GUI-related question.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most probably you are missing the call to super.paintComponent()
If that doesn't fix the problem post your SSCCE code like Campbell suggested.
 
Fernando Piovani
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Most probably you are missing the call to super.paintComponent()
If that doesn't fix the problem post your SSCCE code like Campbell suggested.






I didnt start to work on the GUI yet. I am using netBeans as you can see in the code-generated below. The only thing the program does is display lines that represents a map, using gps coordinates.

Every time i resize the window, or open a new window in front of it, all the drawing is gone.

Oh, and one more question, how can i transform the label that i've draw on into a image, so i can work on the pixels to zoom it and etc.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
:groan:

Never never never use getGraphics() of a Component. Learn about Performing Custom Painting the correct way.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using netBeans as you can see in the code-generated below.


You have every right to take the hard road, but at least you could remove the inane commencts and make your code shorter for posting.
 
Fernando Piovani
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Most probably you are missing the call to super.paintComponent()
If that doesn't fix the problem post your SSCCE code like Campbell suggested.


Yeah, that definitely works. I dont yet understand how and why but its ok... Still, resizing cause the program to reload all drawing, and since i've been working with a huge amout of data it take several time to resize (when growing to larger dimen. ).

My question is:

Why, when i resize to a smaller dimensions didnt reload the drawing process and how does exactly super.paintComponent() works on this matter?
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why, when i resize to a smaller dimensions didnt reload the drawing process and how does exactly super.paintComponent() works on this matter?


Still using getGraphics(), huh?
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and how does exactly super.paintComponent() works on this matter?


I have no idea because this should NOT have fixed your problem. Plus your posted code doesn't even have a paintComponent() method so I have no idea what you are doing.

The whole point of invoking super.paintComponent() is to clear the background of the panel by repainting the panel in its background color which is gray(ish).

Darryl has twice given you the solution.
 
Fernando Piovani
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Why, when i resize to a smaller dimensions didnt reload the drawing process and how does exactly super.paintComponent() works on this matter?


Still using getGraphics(), huh?


Actually, no. I've read the perform custom painting that you show to me, and i done what it says so now it looks like that:

[On Drawing class]

[On Custom_JFrame class]


Its working, but still got this issue with resizing to a bigger window.>
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, this is a performance problem and you should follow what is mentioned in the tutorial:
"To keep our custom painting as efficient as possible, we will track the mouse coordinates and repaint only the areas of the screen that have changed. This is a recommended best practice that will keep your application running as efficiently as possible. "

Refer: Clipping
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic