Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

paintComponent() issue  RSS feed

 
Fiorenza Oppici
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello dear friends.

In this period I've refined some skills and now time has come to review my weak point: handling graphics in java.
I have to write a simple image editor where you can draw onto a predefined image and then save it.

so, I created the class "Vista" which extends a Component and a control class called "GraphicEditor" which is a JFrame. The contstructor tells Vista to retrieve an image and to save it in a BufferedImage, then I overrided method paintComponent in order to draw the image . Unfortunately, there's no image shown and I'm a bit puzzled.

here are the code chunks:

Vista


GraphicEditor


There's no error message and in debug mode the variable img appears to be a full Bufferedimage (so it's not a problem in reading the file). so probably the flaw must be in painting management.

could you help me?

Thanks for your attention.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getPreferredSize() on your component is unlikely to return anything useful, although it depends on what class you're subclassing. JPanel returns 10, 10 by default, for example. You might consider calling setPreferredSize() on Vista first, or simply not defining the frame's size based on it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!